PhantomJS Tutorial
WebPage Module
File System Module
System Module
Web Server Module
Miscellaneous
PhantomJS Useful Resources
Selected Reading
- PhantomJS - Methods
- PhantomJS - Object
- PhantomJS - Environment Setup
- PhantomJS - Overview
- PhantomJS - Home
WebPage Module
- PhantomJS - Child Process Module
- PhantomJS - Events/Callbacks
- PhantomJS - Methods
- PhantomJS - Properties
File System Module
System Module
Web Server Module
Miscellaneous
- PhantomJS - Examples
- PhantomJS - REPL
- PhantomJS - Testing
- PhantomJS - Network Monitoring
- PhantomJS - Page Automation
- PhantomJS - Screen Capture
- Command Line Interface
PhantomJS Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
PhantomJS - Child Process Module
Webpage Child Process Module
The Phantomjs Child process module helps to interact with the sub-processes and talk to them using stdin /stdout/stderr. The child processes can be used for tasks pke printing, sending mail or to invoke programs written in another language. To create a child process module, you need references.
For example −
var process = require("child_process");
Spawn Method
With the spawn child process, you can subscribe to its stdout and stderr streams to get data real-time.
Syntax
Its syntax is as follows −
var spawn = require( child_process ).spawn;
Example
Let us look at an example of the spawn method.
var process = require("child_process") var spawn = process.spawn var child = spawn("cmd", [ /c , dir ]); child.stdout.on("data", function (data) { console.log("spawnSTDOUT---VALUE:", JSON.stringify(data)) }) child.stderr.on("data", function (data) { console.log("spawnSTDERR:", JSON.stringify(data)) }) child.on("exit", function (code) { console.log("spawnEXIT:", code) })
Output
The above program generates the following output.
spawnSTDOUT---VALUE: " Volume in drive C is OS " spawnSTDOUT---VALUE: " Volume Serial Number is 7682-9C1B Directory of C: \phantomjs\bin " spawnSTDOUT---VALUE: "20-05-2017 10:01 <DIR> . 20-05-2017 10:01 <DIR> .. 13-05-2017 20:48 12 a,txt.txt 07-05-2017 08:51 63 a.js 06-05-2017 16:32 120,232 a.pdf 13-05-2017 20:49 spawnEXIT: 0Advertisements