-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathport.ijs
More file actions
44 lines (40 loc) · 985 Bytes
/
port.ijs
File metadata and controls
44 lines (40 loc) · 985 Bytes
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
NB. port utilties - used with Jd/JHS node server
NB. should probably be an addons - for now it can live here
NB. Jd currently loads this script
coclass'jport'
killport=: 3 : 0
'must be single port'assert 1=#y
pid=: getpid y
if. _1~:pid do.
select. UNAME
case. 'Win' do. shell_jtask_'taskkill /f /pid ',":pid
case. do. shell_jtask_'kill ',":pid
end.
end.
i.0 0
)
NB. pid from port - no delay
getpid=: 3 : 0
if. UNAME-:'Win' do.
d=. CR-.~each deb each <;._2 shell'netstat -ano -p TCP | findstr LISTENING | findstr :',":y
if. 0=#d do. _1 return. end.
'port has more than 1 listener'assert 1=#d
d=. ;d
0". (d i:' ')}.d
else.
d=. shell_jtask_ :: 0: 'lsof -P -n -F pfn -i TCP:',":y
if. d-:0 do. _1 return. end.
d=. <;._2 d
if. 3=#d do. 0".}.;{.d return. end.
i=. d i. <'n*:',":y
0".}.;{(i-2){d
end.
)
NB. we expect port to become valid so wait for pid to show up
getpidx=: 3 : 0
for. i.10 do. NB. 1 second
if. 0<d=. getpid y do. d return. end.
6!:3[0.2
end.
_1
)