From 6a86a78eb368c9eaaec693963f8c16b6f0fba81c Mon Sep 17 00:00:00 2001 From: Victor Dramba Date: Fri, 31 Oct 2014 11:58:50 +0200 Subject: [PATCH] code example for child_process --- .../child_process/2000-01-01-child_process.md | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/_posts/api/child_process/2000-01-01-child_process.md b/_posts/api/child_process/2000-01-01-child_process.md index c9481665..b3f34f91 100644 --- a/_posts/api/child_process/2000-01-01-child_process.md +++ b/_posts/api/child_process/2000-01-01-child_process.md @@ -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)) +}) ```