Skip to content

Instantly share code, notes, and snippets.

@MarshalW
Created January 11, 2017 11:31
Show Gist options
  • Save MarshalW/a8c9c6428a6aa9ad0be6f011091a4ad2 to your computer and use it in GitHub Desktop.
Save MarshalW/a8c9c6428a6aa9ad0be6f011091a4ad2 to your computer and use it in GitHub Desktop.
dd命令在nodejs中的调用
// from http://stackoverflow.com/questions/36934749/how-to-get-the-output-of-a-spawned-child-process-in-node-js
var spawn = require('child_process').spawn;
// Create a child process
var child = spawn('dd', ['if=/dev/zero','of=/tmp/test1.img','bs=100m','count=1','conv=noerror,sync']);
child.stdout.on('data',
function(data) {
console.log('ls command output: ' + data);
});
child.stderr.on('data', function(data) {
//throw errors
console.log('stderr: ' + data);
});
child.on('close', function(code) {
console.log('child process exited with code ' + code);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment