diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2017-01-31 00:54:01 -0500 |
---|---|---|
committer | Todd Leonhardt <todd.leonhardt@gmail.com> | 2017-01-31 00:54:01 -0500 |
commit | 1c2983833cd7ae42c99be69fcdcd6d644e264bac (patch) | |
tree | c654b3293bf651e6f8f736c1bc1aac094a9a852d /cmd2.py | |
parent | 6640ce2bab32a25414cd009646ecd7cf3cdfb11d (diff) | |
download | cmd2-git-1c2983833cd7ae42c99be69fcdcd6d644e264bac.tar.gz |
It turns out that setting the stdout and stderr arguments for subprocess.check_call to None doesn't ignore the output, you actually need to pipe it to DEVNULL and that symbol doesn't exist in subprocess namespace prior to Python 3.3
Diffstat (limited to 'cmd2.py')
-rwxr-xr-x | cmd2.py | 9 |
1 files changed, 6 insertions, 3 deletions
@@ -242,8 +242,10 @@ elif sys.platform == 'darwin': # because the child process will block if it generates enough output to a pipe to fill up the OS pipe buffer. # Starting with Python 3.5 there is a newer, safer API based on the run() function. - # test for pbcopy - AFAIK, should always be installed on MacOS - subprocess.check_call('pbcopy -help', shell=True, stdin=subprocess.PIPE, stdout=None, stderr=None) + # Python 3.3+ supports subprocess.DEVNULL, but that isn't defined for Python 2.7 + with open(os.devnull, 'w') as DEVNULL: + # test for pbcopy - AFAIK, should always be installed on MacOS + subprocess.check_call('pbcopy -help', shell=True, stdin=subprocess.PIPE, stdout=DEVNULL, stderr=DEVNULL) can_clip = True except (subprocess.CalledProcessError, OSError, IOError): pass @@ -269,7 +271,8 @@ else: # Running on Linux can_clip = False try: - subprocess.check_call('xclip -o -sel clip', shell=True, stdin=subprocess.PIPE, stdout=None, stderr=None) + with open(os.devnull, 'w') as DEVNULL: + subprocess.check_call('xclip -o -sel clip', shell=True, stdin=subprocess.PIPE, stdout=DEVNULL, stderr=DEVNULL) can_clip = True except AttributeError: # check_call not defined, Python < 2.5 try: |