【发布时间】:2013-02-20 09:59:05
【问题描述】:
我正在尝试从 python 运行一个 c++ 程序。我的问题是每次我跑步:
subprocess.Popen(['sampleprog.exe'], stdin = iterate, stdout = myFile)
它只读取文件的第一行。每次我用一个while循环将它括起来时,它都会因为无限循环而崩溃。有没有其他方法可以读取testcases.txt 中的所有行?
我的示例代码如下:
someFile = open("testcases.txt","r")
saveFile = open("store.txt", "r+")
try:
with someFile as iterate:
while iterate is not False:
subprocess.Popen(['sampleprog.exe'],stdin = iterate,stdout = saveFile)
except EOFError:
someFile.close()
saveFile.close()
sys.exit()
【问题讨论】:
-
只是检查一下,您是想多次调用 sampleprog.exe,基本上在文件中的每一行调用一次,还是想将文件中的所有行作为输入调用一次?
-
实际上我想每行调用一次多次,因为我认为将文件中的所有行作为输入调用一次将取决于用户传递的内容?
标签: python subprocess stdin