问题
I'm trying to call a process from python using subprocess.call as shown below:
from subprocess import call
exePath = 'C:\\Test\\EXE.exe'
inPath = 'C:\\Test\\IN.in'
outPath = 'C:\\Test\\OUT.out'
call([exePath, inPath, outPath])
This prints a few lines from EXE.exe followed by "The handle is invalid" -- but as a string, not as an error, which makes me think it might be a message from the EXE.exe:
Unzipping Solution...
0.0% The handle is invalid.
However when I open cmd.exe and paste in:
C:\Test\EXE.exe C:\Test\IN.in C:\Test\OUT.out
it works fine.
Can someone point me in the right direction?
Thanks!
I'm running Python 2.7 64-bit on Windows 7.
EDIT:
It looks now like a problem in PyDev where the console cannot handle the the stdout from the process overwriting lines. The code runs fine from IDLE. Still looking for a fix for PyDev...
回答1:
I think you're having this issue because PyDev is not a real terminal (i.e.: in Python, os.isatty() will return False when run from PyDev).
If the exe really relies on having a terminal, currently there's not much that PyDev can do...
For now, you can make your call from Python as:
In windows:
popen = subprocess.Popen(['myexe', 'params'], creationflags=subprocess.CREATE_NEW_CONSOLE)
popen.wait()
In Linux (as the CREATE_NEW_CONSOLE is not available):
args = ['xterm', '-e'] + ['myexe', 'params']
popen = subprocess.Popen(args)
popen.wait()
so that it works regardless of who's calling it :)
I think Aptana Studio does have an actual terminal replacement, but there's no PyDev integration to launch things on it...
来源:https://stackoverflow.com/questions/10236260/subprocess-pydev-console-vs-cmd-exe