Jump to content

Hey, i am building a site at work using node js, i need it to run a cmd commands (figured out how to do it with shell_process), but the thing is, that i need to run this as a function that parse the data and process it a bit, then retrun it to be compared, displayed and stroed in a db.

I also need to run it multiple times, so i figured that putting the function in an external js file, but i cant for the life of me, get the output from the function into the main function, not even to a console.log.

 

Is there any way to use the stdout of the shell_process in the main app?

 

I can really use the help, it is holding me back so badly...

Thanks

Link to comment
https://linustechtips.com/topic/1019608-nodejs-child_process/
Share on other sites

Link to post
Share on other sites

You can do this using callbacks: https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback

an example which just calls ls of the current directory and prints it to the console:
 

const exec = require('child_process').exec;

function example() {
    exec('ls', (error, stdout, stderr) => {
        if (error) {
            console.log(stderr);
        }
        else {
            console.log(stdout);
        }
    });
}
example();

 

Gaming build:

CPU: i7-7700k (5.0ghz, 1.312v)

GPU(s): Asus Strix 1080ti OC (~2063mhz)

Memory: 32GB (4x8) DDR4 G.Skill TridentZ RGB 3000mhz

Motherboard: Asus Prime z270-AR

PSU: Seasonic Prime Titanium 850W

Cooler: Custom water loop (420mm rad + 360mm rad)

Case: Be quiet! Dark base pro 900 (silver)
Primary storage: Samsung 960 evo m.2 SSD (500gb)

Secondary storage: Samsung 850 evo SSD (250gb)

 

Server build:

OS: Ubuntu server 16.04 LTS (though will probably upgrade to 17.04 for better ryzen support)

CPU: Ryzen R7 1700x

Memory: Ballistix Sport LT 16GB

Motherboard: Asrock B350 m4 pro

PSU: Corsair CX550M

Cooler: Cooler master hyper 212 evo

Storage: 2TB WD Red x1, 128gb OCZ SSD for OS

Case: HAF 932 adv

 

Link to comment
https://linustechtips.com/topic/1019608-nodejs-child_process/#findComment-12176359
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×