Question
· Oct 29, 2018

redirect stdout to a variable in M and NOT to a file

I'm trying to execute a nodejs process to perform some work on a string from Cache/Mumps over to nodejs, then return the result from nodejs as a string back to the code in Cache and I was looking at the `$ZF` logic - it will let me output the results to a file (i.e. temp.txt) but I dont see a way to just get the output set back to an M variable like (and I know this is not the correct syntax, but just for example)

S myOutput=$ZF(-100, "echo something") ;; wrong syntax but just for example

W myOutput ;; want to write out "something" but of course this doenst work

are there any other options to do this if I cannot use $ZF?

https://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY...

Discussion (4)1
Log in or sign up to continue

Apart from just redirecting to a file, and then reading from that file, the closest you can get is to use a command pipe device:

https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cls...

The main drawback, relative to $zf(-1) or $zf(-100), has been that you couldn't get the exit status of the command. I think that is now possible, but I'm not sure offhand in what versions.

Note that command pipes are not supported in Cache for VMS.

Thank you for the help, here's what I used and did essentially:

    S TRSTR="<tr><td><span>one</span></td><td>two</td></tr>"

    S CMD="node ../pathToNodejsFile/file.js """_TRSTR_""""
    S DEV="|CPIPE|1"
    S EMPTY=0
    open DEV:CMD:0 
    while EMPTY<3 {
        use DEV read line
        set EMPTY=$s($l(line):0,1:$i(EMPTY))
        I line'=""  D
        . use 0 write line,! ; use 0 makes the write go to the default device - if you pass in an IO device you could say `use IO write line` and output to the IO device you have opened if you need to output somewhere other than the default terminal
    }
    use 0 
    close DEV