Last active
February 25, 2020 15:23
-
-
Save Akiyamka/b7ddbe7c9bad60795480da8c1de8d89b to your computer and use it in GitHub Desktop.
node addJson.js command path/to/file.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { spawn } = require('child_process'); | |
const { readFile } = require('fs'); | |
const [app, ...args] = process.argv.slice(2, -1); | |
const pathToJson = process.argv.slice(-1)[0]; | |
readFile(pathToJson, 'utf8', (err, content) => { | |
if (err) { | |
console.error(err); | |
} else { | |
const command = spawn(app, [...args, content]); | |
command.stdout.on('data', data => { | |
console.log('stdout: ' + data.toString()); | |
}); | |
command.stderr.on('data', data => { | |
console.log('stderr: ' + data.toString()); | |
}); | |
command.on('exit', code => { | |
console.log('child process exited with code ' + code.toString()); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment