我正在用Python编写一个脚本,它应该与软件进行通信 "控制台应用程序.exe“(用C写的);最后一个一旦启动就等待一个固定的 从他的“stdin”发出lenght命令(5个字节),并在 他的“stdout”是我应该在Python脚本上读到的输出。在
#//This is the "ConsoleApplication.c" file
#include <stdio.h>
#include <function.h>
char* command[5];
int main()
{
while(1)
{
scanf("%s\n", &command);
output = function(command);
print("%s\n", output);
}
}
#
^{pr2}$
#
有什么建议吗?我怎样才能修好它?在
我试着用
stdout = p.communicate(input='test\n')[0]
但我在运行时收到以下错误: “TypeError:'str'不支持缓冲区接口” 我也试过这个
from subprocess import Popen, PIPE, STDOUT
p = Popen(['ConsoleApplication.exe'], stdout=PIPE, stdin=PIPE, stderr=PIPE)
out, err = p.communicate(input='00056\n'.encode())
print(out)
out, err = p.communicate(input='00043\n'.encode())
print(out)
但我得到一个错误: “值错误:开始通信后无法发送输入”
看来这个问题有你的答案了
Python - How do I pass a string into subprocess.Popen (using the stdin argument)?
使用大众传播()方法
相关问题 更多 >
编程相关推荐