I’m trying to execute a child_process synchronously in node.js (Yes, I know this is bad, I have a good reason) and retrieve any output on stdout, but I can’t quite figure out how…
I found this SO post: node.js execute system command synchronously that describes how to use a library (node-ffi) to execute the command, and this works great, but the only thing I’m able to get is the process exit code. Any data the command executes is sent directly to stdout — how do I capture this?
> run('whoami')
username
0
in otherwords, username is echo’d to stdout, the result of run is 0.
I’d much rather figure out how to read stdout
So I have a solution working, but don’t exactly like it… Just posting here for reference:
I’m using the
node-ffilibrary referenced in the other SO post. I have a function that:>> run-sync-outputrun-sync-outputsynchronously and stores the resultThere’s an obvious issue where if the user doesn’t have write access to the current directory, it will fail. Plus, it’s just wasted effort. :-/