简体   繁体   中英

How to run sh script from node.js project?

My sh script suddenly closes. I'm trying to control sh process by another script. Nohup doesn't help me so I decided to use my Node.js working on forever. So I have found child_process lib but doesn't know how to run sh script on it.

From your comment under your question I assume what you want is this:

const { exec } = require('child_process')

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

The path can be relative or absolute and the file must be executable.

Another way would be to explicitly call sh .

const { exec } = require('child_process')

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM