*** archived ***
The question has come up several times and I saw mixed answers and no quick example
My personal preference is using CPIPE device as you get back exactly the output you will get at the command line interface of your OS .
The tricky thing is to stop reading in time.
The example just displays what you normally see in your console.
it becomes useful if you look for things that you can't get from any $system.whatever()
e.g.
- your servers IP address or addresses depending on your configuration.
- pinging any other server to see if it is still visible on the network
- running nslookup
cmd(command="",test=0) ;
if command="" set command="dir"
quit $$execute(command,test)
execute(cmd,test) Public {
set dev="|CPIPE|1"
set $zt="cls"
set empty=0
open dev:cmd:0
write:test $test,!
else write "pipe failed",! quit 0
while empty<3 {
use dev read line
set empty=$s($l(line):0,1:$i(empty))
use 0 write line,! ;;; or do any kind of analysis of the line
}
cls ;
set $zt="" use 0
close dev
if $ze'["<ENDOFFILE>" w $ze,!
quit $t
}
..
Just run USER>do cmd^Zpipe()
to see if you are allowed to use PIPES
(I just met a narrow-minded security manager that didn't allow the use of pipes to Caché)
or
USER>do cmd^Zpipe("tracert community.intersystems.com")
Tracing route to community.intersystems.com [54.83.203.138] over a maximum of 30 hops:
1 3 ms 1 ms 1 ms 10.10.1.1
2 * * * Request timed out.
3 116 ms 168 ms 132 ms at-vie01b-rc1-ae11-0.aorta.net [84.116.228.201]
4 142 ms 114 ms 115 ms at-vie05d-rc1-ae29-0.aorta.net [84.116.140.2]
5 * * * Request timed out.
6 114 ms 114 ms 115 ms us-nyc01b-rd2-ae9-0.aorta.net [84.116.140.170]
7 118 ms 116 ms 117 ms us-was03a-rd1-ae5-0.aorta.net [84.116.146.142]
8 114 ms 115 ms 114 ms us-was03a-ri1-ae11-0.aorta.net [84.116.130.165]
9 114 ms 116 ms 114 ms 213.46.182.202
10 145 ms 132 ms 132 ms 54.239.111.240
11 115 ms 115 ms 114 ms 54.239.110.152
12 126 ms 136 ms 132 ms 54.239.110.149
13 115 ms 116 ms 114 ms 54.239.108.133
14 129 ms 148 ms 133 ms 52.93.24.94
15 115 ms 114 ms 117 ms 52.93.24.85
16 * * * Request timed out.
17 * * * Request timed out.
18 * * * Request timed out.
19 * * * Request timed out.
20 * * * Request timed out.
21 429 ms 121 ms 114 ms ec2-54-83-203-138.compute-1.amazonaws.com [54.83.203.138]
Trace complete.
Another variants:
Last parameter .args came only with 2017.1
for earlier versions you need to compose it into first argument.
Checking documentation for class %Net.Remote.Utility I find out that it is provided for internal use for Intersystems. So may I use this class in my personal routines without getting any bad surprise?
Source code of class %Net.Remote.Utility is open, so you can use it to make your "RunCommandViaCPIPE" method and already use it.
PS: it's just a wrapper around low-level commands, see Local Interprocess Communication.
I just added a new and more actual example of using the traditional CPIPE device.
It has my personal preference over %Net.Remote.Utility as I feel to have more direct control.
Here is the link to Open Exchange