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.
-
Could you add the code that you tried already?Titulum– Titulum2020-01-14 10:46:21 +00:00Commented Jan 14, 2020 at 10:46
-
1Does this answer your question? Execute a command line binary with Node.jsMAS– MAS2020-01-14 10:47:25 +00:00Commented 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 thatAspin Tojps– Aspin Tojps2020-01-14 11:05:05 +00:00Commented Jan 14, 2020 at 11:05
Add a comment
|
1 Answer
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
});
1 Comment
Aspin Tojps
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