0

I am very new to node.js, I am trying to create a node.js script with the execution of shell script in it.

Here is the code which i have .

var spawn = require('child_process').spawn
var _ = require('underscore');
var deploySh = spawn('sh', [ 'vij.sh' ], {
 cwd: process.env.HOME + '/u/qa/gv/node/scripts',
 env:_.extend(process.env, { PATH: process.env.PATH + ':/usr/local/bin' })
});

and when i try to execute it, i am facing the below issue. Can anyone help me on this?

node vijay
events.js:72
 throw er; // Unhandled 'error' event
 ^
Error: spawn ENOENT
 at errnoException (child_process.js:988:11)
 at Process.ChildProcess._handle.onexit (child_process.js:779:34)
mihai
38.8k11 gold badges64 silver badges90 bronze badges
asked Feb 20, 2014 at 20:55
4
  • 1
    Have you tried using /bin/sh instead of sh? Commented Feb 20, 2014 at 21:03
  • You can drop sh and use spawn('vij.sh') - make sure that vij.sh has #!/bin/sh as the first line. Commented Feb 20, 2014 at 21:08
  • Hi, I have the #!/bin/sh at the first line. I modified the spawn but i get the same issue. Commented Feb 20, 2014 at 21:22
  • Hi Henk, yes i tried /bin/sh instead of sh, its the same error. Commented Feb 20, 2014 at 21:24

2 Answers 2

1

spawn is complaining that it can't find 'sh', use 'bash' instead (you might also need to specify the full path to your script depending on your env setup.)

so I'd try:

  1. spawn('bash', ['vij.sh'], ...

  2. spawn('bash', ['/my/path/to/vij.sh'], ...

  3. spawn('/my/path/to/vij.sh', [], ...

answered Feb 21, 2014 at 0:49
Sign up to request clarification or add additional context in comments.

Comments

0
var spawn = require('child_process').spawn
var _ = require('underscore');
var deploySh = spawn('sh', [ 'vij.sh' ], { 
 // cwd: process.env.HOME + '/u/qa/gv/node/scripts',
 env:_.extend(process.env, { PATH: process.env.PATH + ':/usr/local/bin' })
});

Comment cwd: line no. 4

Until now I don't know what is process.env.HOME value but this worked for me.

nhahtdh
56.9k15 gold badges131 silver badges164 bronze badges
answered Mar 19, 2015 at 2:30

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.