I am currently writing JSON to a file, which I pipe to a shell command:
const { exec } = require('child_process');
fs.writeFileSync('file.json', JSON.stringify(data), 'utf8');
exec(`cat file.json | ./binary_file`, {}, callback);
Rather than writing to a file, how can I safely print/pass this to my binary_file
through Node?
const { exec } = require('child_process');
exec(`echo '${JSON.stringify(data)}' | ./binary_file`, {}, callback);
Is there some way to safely escape strings for shell execution, or is there a better way to accomplish this?
Or, is writing/reading a file any safer?