Question
· Aug 17, 2020

Passing values to the read prompts via cache routine?

Hi Developers 

Is there any way that we can pass the values to the read prompts via cache routine.

For example, we have a couple of reports/routine in our system which accepts some inputs and after taking the inputs it generates some data. Right now it has proper UI and where User enters the value and in routines we have Read statements which accepts those inputs for further processing.

Now we want to schedule all these reports on a task manager on cache and don't want to modify the existing routines  so wanted to check is there any way to pass the values to those "Read statement" via cache routine ?

To make it more clear, following is a test routine,  if we run on terminal it accepts for two inputs, now if we want to trigger the same via a routine, then how to supply these "Read"  command values ?

TestRun
 !,"Enter First Variable Name" a
 !,"Enter Second Variable Name" b
 ^zparas=a_" "_b

quit

 

 

Thanks in Advance.

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

The most simple way  is to redirect your I/O to a TCPport where another job provides you with the expected input:
#1) have a listener:  (any port, I use 7777 for the example)

set listen="|TCP|7777"
open listen:(:7777):0  if '$test write "port busy",! quit
use listen read request
while request'="/*  your end condition */" {
    /* match request for correct reply */
    write reply,!

        }
close listen
     

#2) at your report side all you have to do is

set server =  "|TCP|7777"
open server:("127.0.0.1":7777):0
if '$test write "port busy",! /* termination sequence */ quit
use server

/* launch your program */

here the listener sits on the same machine but it could be any reachable IP-address.
the only critical point is if your program fiddles around changing $IO

 

Hi Dmitriy 
              
Thanks for the reply, problem is that we can run any shell script on UNIX because  our application is migrating to IRIS on Ubuntu, where we will have very minimal OS related features and we cant run anything on shell. and aim to make code OS independent.  

So i am looking for the same thing if that can achieved within Cahe itself. 

I did explore JOB command where I can give principal IO device in the process params, but I am not sure whether it's a right approach for this or not.

Thanks

Paras

As I don't know your version of Caché, I'll suggest that it's quite new. So, I got this code working for IRIS in docker(Ubuntu). Did not check Windows.

auto
  Set fs = ##class(%Stream.FileCharacter).%New()
  Set a = $Random(100)
  Set b = $Random(100)
  Do fs.WriteLine(a)
  Do fs.WriteLine(b)

  Set ccontrol = $Select($ZVersion["IRIS": "iris", 1: "ccontrol")
  Set ccontrol = ccontrol _ $Select($$$isWINDOWS: ".exe", 1: "")
  Set ccontrol = ##class(%File).NormalizeFilename(ccontrol, $System.Util.BinaryDirectory())
  Set instance = ##class(%SYS.System).GetInstanceName()
  ZWrite a,b

  Set stdin = fs.Filename
  Set stdout = ##class(%File).TempFilename()
  Set sc = $zf(-100, "/STDIN="""_stdin_"""/STDOUT="""_stdout_"""", ccontrol, "session", instance, "-U", $Namespace, "TestRun^test")
  ZWrite ^zparas
  Quit 
TestRun
  Write !,"Enter First Variable Name: " R a
  Write !,"Enter Second Variable Name: " R b
  Set ^zparas=a_" "_b
  Quit 

And The output like this

a=17
b=62
^zparas="17 62"