Uh oh!
There was an error while loading. Please reload this page.
forked from EdgeApp/edge-react-gui
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecKeepAlive.js
More file actions
Latest commit
102 lines (90 loc) · 2.27 KB
/
Copy pathexecKeepAlive.js
File metadata and controls
102 lines (90 loc) · 2.27 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// @flow
constchildProcess=require('child_process')
constargv=process.argv
main()
functionpad(num,size){
lets=num+''
while(s.length<size){
s='0'+s
}
returns
}
asyncfunctionmain(){
letcode=0
try{
if(argv.length===4){
code=awaitcallAsync(argv[2],argv[3])
}elseif(argv.length===3){
code=awaitcallAsync(argv[2])
}
}catch(e){
console.log(e)
}
process.exit(code)
}
asyncfunctioncallAsync(cmdString,pipeCmd=''){
returnnewPromise((resolve,reject)=>{
constcmdArray=cmdString.split(' ')
constpipeArray=pipeCmd.split(' ')
letoutCmd
letinCmd
if(pipeCmd){
inCmd=childProcess.spawn(cmdArray[0],cmdArray.slice(1))
outCmd=childProcess.spawn(pipeArray[0],pipeArray.slice(1))
}else{
outCmd=childProcess.spawn(cmdArray[0],cmdArray.slice(1))
}
lettimeoutId
constresetT=()=>{
if(timeoutId){
clearTimeout(timeoutId)
}
timeoutId=setTimeout(()=>{
constdate=newDate(Date.now())
constyear=date.getFullYear()
constmonth=pad(date.getMonth()+1,2)
constday=pad(date.getDate(),2)
consthour=pad(date.getHours(),2)
constmins=pad(date.getMinutes(),2)
console.log(`${year}-${month}-${day}-${hour}:${mins} Waiting...`)
resetT()
},60000)
}
if(inCmd){
inCmd.stdout.on('data',data=>{
outCmd&&outCmd.stdin.write(data)
})
inCmd.stderr.on('data',data=>{
console.log(data.toString())
})
inCmd.on('close',code=>{
if(code===0){
console.log(`process exited with code ${code}`)
outCmd&&outCmd.stdin.end()
}else{
resolve(code)
}
})
}
outCmd.stdout.on('data',data=>{
console.log(data.toString())
resetT()
})
outCmd.stderr.on('data',data=>{
console.log(data.toString())
resetT()
})
outCmd.on('close',code=>{
if(code===0){
console.log(`process exited with code ${code}`)
if(timeoutId){
clearTimeout(timeoutId)
}
resolve(code)
}else{
resolve(code)
}
})
resetT()
})
}