关于python中用subprocess调用exe子进程的问题
我想在python中用subprocess调用一个exe程序tsat_batch.exe,这个程序的路径是:C:\DSATools_8_net\Tsat\bin\tsat...
我想在python中用subprocess调用一个exe程序 tsat_batch.exe, 这个程序的路径是: C:\DSATools_8_net\Tsat\bin\tsat_batch.exe,因为这个程序是一个界面,我要求在这个界面里输入一行字符串:C:/Documents and Settings/tji/Desktop/created tsa files/1.tsa 我自己写的程序是:
import subprocess
p=subprocess.Popen('C:\DSATools_8_net\Tsat\bin\tsat_batch.exe', stdin = subprocess.PIPE, shell = True)
p.stdin.write('C:/Documents and Settings/tji/Desktop/created tsa files/1.tsa')
我是在windows下运行的,报错:
Traceback (most recent call last):
File "C:\Documents and Settings\tji\Desktop\klgkgl.py", line 2, in <module>
p=subprocess.Popen('C:\DSATools_8_net\Tsat\bin\tsat_batch.exe', stdin = subprocess.PIPE, shell = True)
File "C:\Python25\lib\subprocess.py", line 586, in __init__
errread, errwrite) = self._get_handles(stdin, stdout, stderr)
File "C:\Python25\lib\subprocess.py", line 715, in _get_handles
c2pwrite = self._make_inheritable(c2pwrite)
File "C:\Python25\lib\subprocess.py", line 744, in _make_inheritable
DUPLICATE_SAME_ACCESS)
WindowsError: [Error 6] The handle is invalid
哪位兄弟知道应该是什么问题啊,万分感谢! 展开
import subprocess
p=subprocess.Popen('C:\DSATools_8_net\Tsat\bin\tsat_batch.exe', stdin = subprocess.PIPE, shell = True)
p.stdin.write('C:/Documents and Settings/tji/Desktop/created tsa files/1.tsa')
我是在windows下运行的,报错:
Traceback (most recent call last):
File "C:\Documents and Settings\tji\Desktop\klgkgl.py", line 2, in <module>
p=subprocess.Popen('C:\DSATools_8_net\Tsat\bin\tsat_batch.exe', stdin = subprocess.PIPE, shell = True)
File "C:\Python25\lib\subprocess.py", line 586, in __init__
errread, errwrite) = self._get_handles(stdin, stdout, stderr)
File "C:\Python25\lib\subprocess.py", line 715, in _get_handles
c2pwrite = self._make_inheritable(c2pwrite)
File "C:\Python25\lib\subprocess.py", line 744, in _make_inheritable
DUPLICATE_SAME_ACCESS)
WindowsError: [Error 6] The handle is invalid
哪位兄弟知道应该是什么问题啊,万分感谢! 展开
1个回答
展开全部
'C:\DSATools_8_net\Tsat\bin\tsat_batch.exe'
兄弟,这里有问题.
'C:\\DSATools_8_net\\Tsat\\bin\\tsat_batch.exe'
python里单引号晌笑链和双引号是升如一样的东西,perl和shell里的才不一样.反斜杠有转义作用,你要在文本中用反斜杠原字符,就宴孙得再拿一个反斜杠转义一下嘛!!
当然,你也可以写成:
'C:/DSATools_8_net/Tsat/bin/tsat_batch.exe'
兄弟,这里有问题.
'C:\\DSATools_8_net\\Tsat\\bin\\tsat_batch.exe'
python里单引号晌笑链和双引号是升如一样的东西,perl和shell里的才不一样.反斜杠有转义作用,你要在文本中用反斜杠原字符,就宴孙得再拿一个反斜杠转义一下嘛!!
当然,你也可以写成:
'C:/DSATools_8_net/Tsat/bin/tsat_batch.exe'
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询