In a 64-bit system with 32 bit python 2.7 installed I am trying to do the following:
import subprocess
p = subprocess.call('dir', shell=True)
print p
But this gives me:
Traceback (most recent call last):
File "test.py", line 2, in <module>
p = subprocess.call('dir', shell=True)
File "C:\Python27\lib\subprocess.py", line 522, in call
return Popen(*popenargs, **kwargs).wait()
File "C:\Python27\lib\subprocess.py", line 709, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 957, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
If I in the terminal do...
dir
...it of course prints the present folder content.
I have tried to change the shell parameter to shell=False.
Edit: Actually I cannot call any executable on the path with subprocess.call(). The statement p = subprocess.call('dir', shell=True) works fine on another machine and I think that it is related.
If I do
subprocess.call('PATH', shell=True)
then I get
Traceback (most recent call last):
File "test.py", line 4, in <module>
subprocess.call('PATH', shell=True)
File "C:\Python27\lib\subprocess.py", line 522, in call
return Popen(*popenargs, **kwargs).wait()
File "C:\Python27\lib\subprocess.py", line 709, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 957, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
If I do:
import os
print os.curdir
then I get
.
All of the above is executed in the terminal started in Administrator mode.
diris not an executable, it is a console-only command. Why not useos.listdir()instead? - Martijn Pieters♦p = subprocess.call('dir', shell=True)works fine on another machine and I think that it is related. I wanted to simplify my question as much as possible so I only brought up the example with 'dir'. I updated the question... - tuple_cat