I have a program that gets output from another program which runs on the new windows subsystem for linux. I have written a python program that runs from the windows system, but will execute the linux program using python subprocess module. If this is confusing see the example below.
However, when I do this I find that when called through python subprocess, windows cannot find bash program.
example on the commandline or powershell in windows:
C:\>bash -c "echo hello world!"
hello world!
C:\>python
Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess as s
>>> s.call('bash -c "echo hello world"'.split())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "c:\Python27-32\lib\subprocess.py", line 524, in call
return Popen(*popenargs, **kwargs).wait()
File "c:\Python27-32\lib\subprocess.py", line 711, in __init__
errread, errwrite)
File "c:\Python27-32\lib\subprocess.py", line 948, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
>>> s.call('bash -c "echo hello world"'.split(),shell=True)
'bash' is not recognized as an internal or external command,
operable program or batch file.
1
I thought maybe it wasn't loading my path settings somehow so I put in the full address of the bash program.
>>> s.call(b,shell=True)
'C:\Windows\System32\bash.exe' is not recognized as an internal or external command,
operable program or batch file.
1
EDIT : I realize my command might be giving a problem since o am splitting on spaces and the "echo hello world" is one argument, but trying the same thing with bash -c ls
also gives the same error