user3334590
user3334590

Reputation: 1

shell script on node.js

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)

Upvotes: 0

Views: 873

Answers (2)

Sudhir Meena
Sudhir Meena

Reputation: 1

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.

Upvotes: 0

smertrios
smertrios

Reputation: 3505

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', [], ...

Upvotes: 1

Related Questions