【发布时间】:2021-12-23 07:16:36
【问题描述】:
我想生成一个子进程,然后在稍后向它发送一个参数,然后它会执行。我怎样才能做到这一点? (NodeJS,在 Mac 上)
例如,我有一个执行脚本文件的命令:
osascript script-test.scpt
这个命令可以在终端运行,也可以用 exec 运行,像这样:
const { exec } = require('child_process')
var script = 'osascript script-test.scpt'
exec(script)
但是如何让它在已经运行的子进程中工作呢?
我尝试了以下方法,但没有任何反应(没有错误,也没有活动):
const { spawn } = require('child_process')
var process = spawn('osascript')
...
[at some later point (after spawned process has been created)]
process.stdin.write('script-test.scpt')
【问题讨论】:
标签: node.js stdin child-process spawn osascript