Merge pull request #12694 from dvictor/patch-1

code example for child_process
gh-pages
Ariya Hidayat 2014-11-16 10:59:26 -08:00
commit cd0daacccf
1 changed files with 24 additions and 1 deletions

View File

@ -10,5 +10,28 @@ The child_process module allows you to invoke subprocesses and communicate with
To start using, you must `require` a reference to the `child_process` module:
```javascript
var childProcess = require('child_process');
var process = require("child_process")
var spawn = process.spawn
var execFile = process.execFile
var child = spawn("ls", ["-lF", "/rooot"])
child.stdout.on("data", function (data) {
console.log("spawnSTDOUT:", JSON.stringify(data))
})
child.stderr.on("data", function (data) {
console.log("spawnSTDERR:", JSON.stringify(data))
})
child.on("exit", function (code) {
console.log("spawnEXIT:", code)
})
//child.kill("SIGKILL")
execFile("ls", ["-lF", "/usr"], null, function (err, stdout, stderr) {
console.log("execFileSTDOUT:", JSON.stringify(stdout))
console.log("execFileSTDERR:", JSON.stringify(stderr))
})
```