Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法使用节点exec执行python_Python_Node.js_Child Process - Fatal编程技术网

无法使用节点exec执行python

无法使用节点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) }

使用node的
子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
也在等待一些数据