Run a binary from Node.JS and relay the behavior exactly on the console, including prompts
You can use 'inherit'
for the stdio option of spawn:
const spawn = require( 'child_process' ).spawn;
spawn( '/path/to/binary', [], { stdio: 'inherit' } );
Execute and get the output of a shell command in node.js
This is the method I'm using in a project I am currently working on.
var exec = require('child_process').exec;
function execute(command, callback){
exec(command, function(error, stdout, stderr){ callback(stdout); });
};
Example of retrieving a git user:
module.exports.getGitUser = function(callback){
execute("git config --global user.name", function(name){
execute("git config --global user.email", function(email){
callback({ name: name.replace("\n", ""), email: email.replace("\n", "") });
});
});
};
How to execute node command in a node app?
run it sequentially with execSync
const execSync = require('child_process').execSync;
//...
switch (arg) {
case "React App":
console.log(`npx create-react-app ${projectName}`);
execSync(`npx create-react-app ${projectName}`);
console.log(`cd ${projectName}`);
execSync(`cd ${projectName}`);
console.log(`npm start`);
execSync(`npm start`);
break;
case "Next App":
console.log(`npx create-next-app@latest ${projectName}`);
execSync(`npx create-next-app@latest ${projectName}`);
console.log(`cd ${projectName}`);
execSync(`cd ${projectName}`);
console.log(`npm dev`);
execSync(`npm dev`);
break;
}
Execute bash script via Node.js and include command line parameters
The second parameter in spawn is an array of arguments to pass to the command. So I think you almost have it but instead of concating the params to the path pass them in as an array:
var spawn = require('child_process').spawn;
var params = ['pathToScript','run', '-silent'];
spawn('bash', params, {
stdio: 'ignore',
detached: true
}).unref();
Related Topics
Prevent Onmouseout When Hovering Child Element of the Parent Absolute Div Without Jquery
Change CSS of Selected Text Using JavaScript
Canvas2D Todataurl() Different Output on Different Browser
Set Active Tab Style With Angularjs
Submit Form Fields Inside Display:None Element
How to Make the Browser Wait to Display the Page Until It's Fully Loaded
Why JavaScript This.Style[Property] Return an Empty String
How to Remove a Style Added With .Css() Function
Jquery Svg, Why Can't I Addclass
How to Hide a ≪Option≫ in a ≪Select≫ Menu With Css
How to Use Jquery to Wait For the End of Css3 Transitions
Can You Control Gif Animation With JavaScript
Ios 8 Removed "Minimal-Ui" Viewport Property, Are There Other "Soft Fullscreen" Solutions
Bootstrap Modal Appearing Under Background