Question
· Nov 15, 2023

The ability to start a program from within cache

I am trying to execute a program from within cache using a $zf call

S X=$ZF(-1,"C:\""Program Files (x86)""\Car-Part\Messaging\iCPM.exe")

For the sake of this post I changed it to open notepad

S X=$ZF(-1,"C:\Windows\notepad.exe")

If I call it directly from terminal notepad opens and all is happy.  

If I add it to a program we use to run certain tasks once an hour or even every 10 minutes it will fire off notepad but it will be in the background.

The messaging application we use will not work at all in the background and needs to be in the foreground.  

I have tried everything myself and 3 other developers can think of but it's always the same result in the background. I even contacted Intersystems and talked with a very helpful rep but we still couldn't figure it out.

Does anyone have any ideas?

 

Thanks!

Product version: Caché 2017.1
$ZV: 2017.2.2.865.3
Discussion (2)1
Log in or sign up to continue

You need an interactive user's system to run this without any user interaction?

If it doesn't matter who runs it and it doesn't take any serious resources and could run unnoticed then could you set a global that is checked by some code that is regularly run by a group of users? The first interactive process that finds the global could do your $ZF for you? Say SET ^GLOBAL("RUN NOTEPAD")=$H

Then in the common piece of code L +^GLOBAL("RUN NOTEPAD"):0 I $T {S:$D(^GLOBAL("RUN NOTEPAD")) X=$ZF(-1,"C:\Windows\notepad.exe") K ^GLOBAL("RUN NOTEPAD") L -K ^GLOBAL("RUN NOTEPAD")}

Otherwise I think you need to fix the destination program so it will run in the background.

First, just to let you know that even back with Cache 2017.x.x, $ZF(-1) & $ZF(-2) are deprecated and shouldn't be used for new code. $ZF(-100) should be used instead. As $ZF(-100) is more powerful anyway, I would suggest reading up on it:

https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cls?KEY=RCOS_fzf-100

With $ZF(-100) you can redirect input and output to files or other devices which may help you run the task you're requiring in the background. Note that I don't know (at least in a Windows environment) if you can successfully run a job in the background and still have interactive access to that process. There's a note in the documentation above that states that /ASYNC jobs use the null device for input if it's not redirected from a file. I don't know if you can redirect from a device instead.

Hope this helps!