Created
January 11, 2017 11:31
-
-
Save MarshalW/a8c9c6428a6aa9ad0be6f011091a4ad2 to your computer and use it in GitHub Desktop.
dd命令在nodejs中的调用
This file contains 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
// 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