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.
            Asked
            
        
        
            Active
            
        
            Viewed 2,095 times
        
    0
            
            
        - 
                    Could you add the code that you tried already? – Titulum Jan 14 '20 at 10:46
- 
                    1Does this answer your question? [Execute a command line binary with Node.js](https://stackoverflow.com/questions/20643470/execute-a-command-line-binary-with-node-js) – MAS Jan 14 '20 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 – Aspin Tojps Jan 14 '20 at 11:05
1 Answers
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
});
 
    
    
        Jen
        
- 1,206
- 9
- 30
- 
                    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 – Aspin Tojps Jan 14 '20 at 12:39
