子进程:PyDev控制台与cmd.exe [英] subprocess: PyDev console vs. cmd.exe

查看:216
本文介绍了子进程:PyDev控制台与cmd.exe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用subprocess.call从python调用一个进程,如下所示:

 从子进程import call 

exePath ='C:\\Test\\EXE.exe'
inPath ='C:\\Test\\IN.in'
outPath ='C:\\Test\\OUT.out'
call([exePath,inPath,outPath])

这会从EXE.exe打印几行,后跟句柄无效 - 但作为一个字符串,而不是一个错误,这使我认为它可能是一个消息从EXE.exe:

 解压缩解决方案... 
0.0%句柄无效。



但是当我打开cmd.exe并粘贴:

  C:\Test\EXE.exe C:\Test\IN.in C:\Test\OUT.out 

它工作正常。



有人可能指向我的方向?



我在Windows 7上运行Python 2.7 64位。



EDIT:



现在看起来像PyDev中的问题,控制台无法处理stdout从进程覆盖线。代码从IDLE运行良好。仍在寻找PyDev的修复...

解决方案

我认为你有这个问题,因为PyDev不是一个真正的终端(即:在Python中,从PyDev运行时,os.isatty()将返回False)。



如果exe真的依赖于有一个终端, PyDev可以做...



现在,你可以使用Python来调用:



  popen = subprocess.Popen(['myexe','params'],creationflags = subprocess.CREATE_NEW_CONSOLE)
popen.wait()



在Linux中(因为CREATE_NEW_CONSOLE不可用):

  args = ['xterm','-e'] + ['myexe','params'] 
popen = subprocess。 Popen(args)
popen.wait()

it:)



我认为Aptana Studio有一个实际的终端替换,但没有PyDev集成来启动它... ...


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...

解决方案

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...

这篇关于子进程:PyDev控制台与cmd.exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆