0

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.

3
  • Could you add the code that you tried already? Commented Jan 14, 2020 at 10:46
  • 1
    Does this answer your question? Execute a command line binary with Node.js Commented Jan 14, 2020 at 10:47
  • @Titulum my code doesn't different from the code in the links below. I just can't find a code with link to specific .sh file. So Im not sure how to do that Commented Jan 14, 2020 at 11:05

1 Answer 1

2

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
});
Sign up to request clarification or add additional context in comments.

1 Comment

ty. I already found a solution (same code but using 'shelljs' lib). I just use exec('./file.sh'... without sh prefix. Thats works for me

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.