click
click copied to clipboard
Use subprocess instead of os.system
There are various places, mostly in _termui_impl
, that use os.system
. Python has recommended using subprocess
(call
, Popen
) instead for quite some time. Replace all occurrences of os.system
with subprocess.call
or Popen
, passing a list of args (not a string command). This will require a bit of care since there's a few places that write command strings that can't be directly translated to args lists, and we should ensure the expected commands continue to work on Windows, Mac, and Linux.
What's the benefit of using subprocess here? Specially the shell mode of subprocess (which woudl be needed here) has the same issues as os.system
@mitsuhiko Why would the shell mode be needed? The only shell constructs currently used in the os.system()
calls are redirects (which can be reproduced with the stdout=
and stderr=
arguments to Popen()
) and subshelling with (cmd)
(which appears to be superfluous, and even if it's not, it should be reproduceable with subprocess.call(['sh', '-c', 'cmd'])
). Is this about the idiosyncratic command-splitting on Windows?
The pager support is directly taken from pyhelp in the stdlib. Last time I tried to replace it with subprocess I ran into a lot of annoying issues on windows. Can't remember the details but effectively it didn't work like I wanted unless it ran through a shell indirection.
Hi, I wanna fix this issue, Can i know what is the current status? and why was this stalled