child_process-examples.js 672 B

123456789101112131415161718192021222324252627
  1. var spawn = require("child_process").spawn
  2. var execFile = require("child_process").execFile
  3. var child = spawn("ls", ["-lF", "/rooot"])
  4. child.stdout.on("data", function (data) {
  5. console.log("spawnSTDOUT:", JSON.stringify(data))
  6. })
  7. child.stderr.on("data", function (data) {
  8. console.log("spawnSTDERR:", JSON.stringify(data))
  9. })
  10. child.on("exit", function (code) {
  11. console.log("spawnEXIT:", code)
  12. })
  13. //child.kill("SIGKILL")
  14. execFile("ls", ["-lF", "/usr"], null, function (err, stdout, stderr) {
  15. console.log("execFileSTDOUT:", JSON.stringify(stdout))
  16. console.log("execFileSTDERR:", JSON.stringify(stderr))
  17. })
  18. setTimeout(function () {
  19. phantom.exit(0)
  20. }, 2000)