Python 和子进程
这是我正在编写的脚本。 它应该为下面的循环运行一个 .exe 文件。 (顺便说一下,不确定它是否可见,但 for el in ('90','52.6223',...) 在循环之外并与其余部分形成嵌套循环)我不确定顺序是否正确或什么不。 另外,当 .exe 文件运行时,它会吐出一些内容,我需要将某一行打印到屏幕上(因此您会看到 AspecicLinfe= ... )。 任何有用的答案都会很棒!
for el in ('90.','52.62263.','26.5651.','10.8123.'):
if el == '90.':
z = ('0.')
elif el == '52.62263.':
z = ('0.', '72.', '144.', '216.', '288.')
elif el == '26.5651':
z = ('324.', '36.', '108.', '180.', '252.')
else el == '10.8123':
z = ('288.', '0.', '72.', '144.', '216.')
for az in z:
comstring = os.path.join('Path where .exe file is')
comstring = os.path.normpath(comstring)
comstring = '"' + comstring + '"'
comstringfull = comstring + ' -el ' + str(el) + ' -n ' + str(z)
print 'The python program is running this command with the shell:'
print comstring + '\n'
process = Popen(comstring,shell=True,stderr=STDOUT,stdout=PIPE)
outputstring = myprocesscommunicate()
print 'The command shell returned the following back to python:'
print outputstring[0]
AspecificLine=linecache.getline(' ??filename?? ', # ??
sys.stderr.write('az', 'el', 'AREA' ) # ??
This is for a script I'm working on. It's supposed to run an .exe file for the loop below. (By the way not sure if it's visible but for el in ('90','52.6223',...) is outside the loop and makes a nested loop with the rest) I'm not sure if the ordering is correct or what not. Also when the .exe file is ran, it spits some stuff out and I need a certain line printed to the screen (hence where you see AspecificLinfe= ... ). Any helpful answers would be great!
for el in ('90.','52.62263.','26.5651.','10.8123.'):
if el == '90.':
z = ('0.')
elif el == '52.62263.':
z = ('0.', '72.', '144.', '216.', '288.')
elif el == '26.5651':
z = ('324.', '36.', '108.', '180.', '252.')
else el == '10.8123':
z = ('288.', '0.', '72.', '144.', '216.')
for az in z:
comstring = os.path.join('Path where .exe file is')
comstring = os.path.normpath(comstring)
comstring = '"' + comstring + '"'
comstringfull = comstring + ' -el ' + str(el) + ' -n ' + str(z)
print 'The python program is running this command with the shell:'
print comstring + '\n'
process = Popen(comstring,shell=True,stderr=STDOUT,stdout=PIPE)
outputstring = myprocesscommunicate()
print 'The command shell returned the following back to python:'
print outputstring[0]
AspecificLine=linecache.getline(' ??filename?? ', # ??
sys.stderr.write('az', 'el', 'AREA' ) # ??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
shell=True
是错误的,因为这会不必要地调用 shell。相反,请执行以下操作:
Using
shell=True
is wrong because that needlessy invokes the shell.Instead, do this: