如何从node.js项目运行sh脚本?

我的sh脚本突然关闭。我正在尝试通过另一个脚本控制sh进程。 Nohup并没有帮助我,所以我决定永远使用我的Node.js。因此,我找到了child_process lib,但不知道如何在其上运行sh脚本。

MYLIFEA 回答:如何从node.js项目运行sh脚本?

根据您对问题的评论,我假设您想要的是

const { exec } = require('child_process')

exec('path/to/your/specific/file.sh',(err,stdout,stderr) => {
    // do whatever you want
});

路径可以是相对路径,也可以是绝对路径,并且文件必须是可执行文件。

另一种方法是显式调用sh

const { exec } = require('child_process')

exec('sh path/to/your/specific/file.sh',stderr) => {
    // do whatever you want
});
本文链接:https://www.f2er.com/2772373.html

大家都在问