nodejs child_process通信问题
现有两个文件,且在同一目录下
test.py
print("py 启动")
x = input()
if(x == "1"):
print("recived!")
index.js
const {
exec
} = require("child_process")
const test = exec("python test.py", {
cwd: process.cwd()
})
test.stdin.write("1")
test.stdout.on("data", (data) => {
console.log(data.toString());
})
index.js代码写的有问题,要求就是用index去执行python脚本,且往脚本里面输入1。并打印出结果,test.py代码不可改动,index.js代码随便改,换个库都行,只要实现下效果。
即执行node index,index.js调用python脚本,并往里面输入了1,并打印出结果
py 启动
1
recived!