I am using python3 under git-bash environment, and sometimes it does not run shell command well.
#!/usr/bin/env python3
import subprocess as sp
print("hello")
print(sp.getoutput("ls -l")) # This works.
print(sp.getoutput("date")) # This hangs and cannot terminate with ctrl-c.
This does not happen when running under normal linux/bash environment.
Then I come across this one: Python not working in the command line of git bash.
I can run using "winpty python ...", however it still cannot terminate even with ctrl-c.
I take back, getoutput("date") hangs but check_output works.
datecommand in git bash ?dateit starts should be the same as the one bash starts; if it's the former, then not so much). Another important difference is that for a Cygwin python, anywhere it's told to run a shell will startsh; if it's a Windows one, it'll try to startcmd. I would only expectsp.getoutput("ls -l")to ever work with a Windows-built Python; for a Cygwin one or or a more legitimately UNIXy system it needs to besp.getoutput(["ls", "-l"])to work at all.sp.getoutput("ls -l", shell=True)should also work on UNIXy systems, or Python interpreters built for cygwin/msys/etc)datefrom a more UNIXy Python interpreter, or a more UNIXydatefrom a native-Windows Python interpreter is liable to cause surprises like those discussed in the other question you linked.