click icon indicating copy to clipboard operation
click copied to clipboard

Use subprocess instead of os.system

Open davidism opened this issue 5 years ago • 4 comments

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.

davidism avatar Feb 22 '20 17:02 davidism

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 avatar Feb 22 '20 19:02 mitsuhiko

@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?

jwodder avatar Feb 22 '20 19:02 jwodder

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.

mitsuhiko avatar Feb 22 '20 19:02 mitsuhiko

Hi, I wanna fix this issue, Can i know what is the current status? and why was this stalled

harivamsi9 avatar Jun 05 '22 12:06 harivamsi9