subprocess: PyDev console vs. cmd.exe

徘徊边缘 提交于 2019-12-24 04:15:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!