I'm using python 3.5 on Mac OS X Sierra
The following code works as expected, printing 'hello world' 5 times:
for _ in range(5):
print(subprocess.check_output(['/bin/bash', '-i', '-c', 'echo hell world']))
while this one causes the script to stop, after printing the directory listing only once.
for _ in range(5):
print(subprocess.check_output(['/bin/bash', '-i', '-c', 'ls']))
displays
... my directory listing ...
[2]+ Stopped python demo.py
I have aliased my ls in ~/.bashrc as ls -alf. If I remove the alias, the program seems to work fine. Is there something wrong with starting bash in interactive mode?
EDIT:
Interestingly, I can hack the command to force the correct behavior:
for _ in range(5):
print(subprocess.check_output(['/bin/bash', '-i', '-c', 'echo; ls']))
Now ls doesn't kill the script anymore, regardless of whether it's aliased or not. Any idea?