First of all, I am a complete noob and started using Node.JS yesterday (this was my first time I used Linux in years), so please be beautiful and explicit
I am currently creating a Node.JS program that should, among other things, run shell commands (basically: mount a USB drive). I am currently using
var spawn = require('child_process').spawnSync; function shspawn(command) { spawn('sh', ['-c', command], { stdio: 'inherit' }); } shspawn('echo Hello world'); shspawn('mkdir newdir');
etc .. this is a really convenient way to do this for me. The problem is that I would like to save the output, for example, the "ls" command in a variable, like
var result = shspawn('ls -l')
I read a few examples on the Internet, but they rarely use spawn, and when they do this, it doesnโt work for me (I think I can do something wrong, but again I am a noob in Node)
If you have an idea better than using child_process_spawnSync, I am open to any idea, but I would like to keep my program as long as possible without packages :)
EDIT: I need it to work synchronously! This is why I started using spawnSync. I will use some commands, such as dd, which take time and must be completed completely before the program moves to another command.