-
Notifications
You must be signed in to change notification settings - Fork 0
/
13_child_process.js
38 lines (30 loc) · 1.01 KB
/
13_child_process.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/**
* Child Processes Module - It allows you to execute external processes in your environment
* Two main function to execute this processes -
* 1. exec (execute)
* 2. spawn
*/
//all child_processes are synchronous by default
const cp = require("child_process")
// cp.exec('open https://linkedin.com/learning')
// cp.exec('open -a Terminal .')
// cp.exec("lst", (err, data, standardError) => {
// if(err)
// throw err
// data && console.log(data)
// standardError && console.log(standardError)
// })
// cp.exec("node 12_streams", (err, data, standardError) => {
// if(err)
// throw err
// data && console.log(data)
// standardError && console.log(standardError)
// })
/**
* Spawn -> Execute process is design to handle synchronous function
* Processes that are waiting for input then execute -> we use spawan in this case
*/
const questionApp = cp.spawn("node", ["12_streams.js"])
questionApp.stdout.on("data", data => {
console.log('app data', data)
})