child_process-examples.js 686 B

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