无法使用节点exec执行python
使用node的无法使用节点exec执行python,python,node.js,child-process,Python,Node.js,Child Process,使用node的子spawnexec基本上模仿了shell,所以我应该能够做到 exec('python' , (error, stdout, stderr) => { if (error || stderr) { console.log('exec error ' , error ) console.log('exec stderr ' , stderr) } else { console.log('exec output ' , stdout) }
子spawn
exec
基本上模仿了shell,所以我应该能够做到
exec('python' , (error, stdout, stderr) => {
if (error || stderr) {
console.log('exec error ' , error )
console.log('exec stderr ' , stderr)
} else {
console.log('exec output ' , stdout)
}
})
或
但我什么也没得到,甚至连错误都没有
我错过了什么
感谢
python
命令要求将一些数据写入stdin。您可以使用exec返回的subprocess对象写入该数据:
const { exec } = require('child_process');
const subprocess = exec('python' , (error, stdout, stderr) => {
if (error || stderr) {
console.log('exec error ' , error )
console.log('exec stderr ' , stderr)
} else {
console.log('exec output ' , stdout)
}
})
subprocess.stdin.write('print("test");');
subprocess.stdin.end()
可能
hello.py
也在等待一些数据。python
命令要求将一些数据写入stdin。您可以使用exec返回的subprocess对象写入该数据:
const { exec } = require('child_process');
const subprocess = exec('python' , (error, stdout, stderr) => {
if (error || stderr) {
console.log('exec error ' , error )
console.log('exec stderr ' , stderr)
} else {
console.log('exec output ' , stdout)
}
})
subprocess.stdin.write('print("test");');
subprocess.stdin.end()
可能hello.py
也在等待一些数据