node.js - Spawning child_process in NodeJS with valid HOME folder set -



node.js - Spawning child_process in NodeJS with valid HOME folder set -

i'm trying spawn process in nodejs accesses home folder, , can't see, either of options below work.

var spawn = require('child_process').spawn, options = {stdio: 'inherit', env: process.env}; spawn('ls', ['~/'], options); spawn('ls', ['$home'], options);

output

ls: ~/: no such file or directory ls: $home: no such file or directory

i've verified options.env.home set, thought i'm doing wrong?

update

so ended doing create use-case work (using script instead of ls):

spawn('script', [process.env.home], options);

then, within of script:

#!/usr/bin/env bash export home=$1

i still don't understand why options.env.home not seem work expected.

process.env.home want. utilize so:

var spawn = require('child_process').spawn, options = {stdio: 'inherit'}; var ls = spawn('ls', [process.env.home]); ls.stdout.on('data', function(data){ console.log(string(data)); }); ls.stderr.on('data', function(data){ console.log(string(data)); });

then can set home in shell when invoking node script:

home='/tmp'; node ls.js

alternatively, don't have overload home. utilize whatever variable export first, , access through process.env.:

export foo='/tmp'; node ls.js

node.js child-process

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -