How to execute external unix/windows commands from COS
I would like to invoke some unix/windows commands from COS, any API could do that?
Also, I would like to set up some Environment Variables for this process which would execute the above external command.
Anyway to achieve that?
Thanks for your help.
Comments
Joining this question.
It would also be nice if someone could describe how to catch and process I/O at this point. Ideally I am looking for something like:
do pseudocode.Write("ipconfig")
// loop may go here
set data = pseudocode.Read()
// loop may close here
// ... and the data is the stdout of the process!
Thanks.
THanks.
You might want to check this out.
https://community.intersystems.com/post/how-do-i-get-list-files-directo…
At a low level, there are two options:
Pipes / command pipes - useful if you want to be able to read command output OR write to the command. Unfortunately, you have to pick one or the other. To answer Nikita's question - maybe there's some tricky way around this by building a command that redirects stdout to a file, which is read using a separate device?
$zf(-1) / $zf(-2) - these are a little bit easier to use. $zf(-1) spawns a child process and waits for it to return; $zf(-2) doesn't wait.
Needless to say, if you're building these into an application, make sure that you're careful about building user input into the commands that you execute. ![]()
Here's the wrapper I usually use.