0
我试图通过python运行一个exe文件,同时转储用户输入并输出到日志文件。对于EXE转储外部程序的标准输入和标准输出
源文件:编译上述文件后,
//test.c
#include<stdio.h>
void main()
{
int a=0;
printf("Enter no:\n");
scanf("%d",&a);
printf("You entered %d",a);
}
,我试图通过蟒蛇
#Dumpinputoutput.py
file="log.txt"
fo=open(file, "w")
subprocess.call(["test.exe"],stdout=fo,stderr=fo)
fo.close()
test.exe的上执行的脚本运行,
log.txt是:
Enter no:
You entered 54
而不是
Enter no:
54
You entered 54
我希望用户的输入也要包含在日志文件中,这可能吗?
我也尝试subprocess.peopen,但得到相同的。
[脚本](http://unixhelp.ed.ac.uk/CGI/man-cgi?script)确实如此,但在Windows上不可用(除了可能通过[cygwin](http:// www.cygwin.com/)),而不是Python。 –
@PhilFrost:我安装了cygwin,它没有脚本命令,我尝试安装该命令,setup.exe -q -P脚本..但仍然显示命令未找到.. ?? – everlasto