我尝试创建使用MAC OS的子模块的子进程。 下面是我的代码:
import subprocess
p = subprocess.Popen("app",
stdin = subprocess.PIPE,
stdout = subprocess.PIPE,
stderr = subprocess.PIPE,
shell = True)
p.stdin.write(bytes("3\n", "ascii"))
p.stdin.write(bytes("4\n", "ascii"))
print(p.stdout.read())
应用程序的源代码是:
#include <iostream>
using namespace std;
int main()
{
int x, y;
cout << "input x: " << endl;
cin >> x;
cout << "input y: " << endl;
cin >> y;
cout << x << " + " << y << " = " << x + y << endl;
return 0;
}
当我执行的Python代码,输出为:
b''
为什么输出是一个奇怪的字符串?