diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2017-01-30 22:10:27 -0500 |
---|---|---|
committer | Todd Leonhardt <todd.leonhardt@gmail.com> | 2017-01-30 22:10:27 -0500 |
commit | 450b7b37ef92fa529d07c9d348aaae4a5c036f9f (patch) | |
tree | b209813900ba12ed7c7d430f32b6ce18aa87da7c /cmd2.py | |
parent | 97bde4901070048a676bd8acff5d492fd587c58c (diff) | |
download | cmd2-git-450b7b37ef92fa529d07c9d348aaae4a5c036f9f.tar.gz |
A more complete fix for the subprocess.check_call() blocking issue addressed in PR #25.
Diffstat (limited to 'cmd2.py')
-rwxr-xr-x | cmd2.py | 13 |
1 files changed, 9 insertions, 4 deletions
@@ -208,6 +208,7 @@ to be installed on operating system. %s""" if sys.platform == "win32": + # Running on Windows try: import win32clipboard @@ -234,11 +235,15 @@ if sys.platform == "win32": write_to_paste_buffer = get_paste_buffer elif sys.platform == 'darwin': + # Running on Mac OS X can_clip = False try: + # Warning: subprocess.call() and subprocess.check_call() should never be called with stdout=PIPE or stderr=PIPE + # 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, stdout=subprocess.PIPE, stdin=subprocess.PIPE, - stderr=subprocess.PIPE) + subprocess.check_call('pbcopy -help', shell=True, stdin=subprocess.PIPE, stdout=None, stderr=None) can_clip = True except (subprocess.CalledProcessError, OSError, IOError): pass @@ -261,10 +266,10 @@ elif sys.platform == 'darwin': write_to_paste_buffer = get_paste_buffer else: + # Running on Linux can_clip = False try: - subprocess.check_call('xclip -o -sel clip', shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE, - stderr=subprocess.PIPE) + subprocess.check_call('xclip -o -sel clip', shell=True, stdin=subprocess.PIPE, stdout=None, stderr=None) can_clip = True except AttributeError: # check_call not defined, Python < 2.5 try: |