使用子进程调用/ popen从另一个python脚本执行python脚本

时间:2014-03-14 20:00:05

标签: python shell wxpython

我遇到了从不同的python脚本执行python脚本的问题:

filePath = "C:\Desktop\TestScripts\test.py"
####subprocess.call(filePath, shell = True)

child = subprocess.Popen(filePath, shell=True, stderr=subprocess.PIPE)
   while True:
        out = child.stderr.read(1)
        if out == '' and child.poll() != None:
           break
        if out != '':
           sys.stdout.write(out)
           sys.stdout.flush()

当我执行此操作时,我得到了:

'C:\Desktop\TestScripts\' is not recognized as an internal or external command,
operable program or batch file.

我无法解释上述错误。任何建议都将受到高度赞赏。

1 个答案:

答案 0 :(得分:1)

请注意,错误是说无法找到文件'C:\Desktop\TestScripts\'。文件名被截断,因为'\t'是TAB字符。

In [156]: print('C:\Desktop\TestScripts\test.py')
C:\Desktop\TestScripts  est.py

改为使用raw string r'C:\Desktop\TestScripts\test.py'

In [157]: print(r'C:\Desktop\TestScripts\test.py')
C:\Desktop\TestScripts\test.py
相关问题