Question
Paras Batheja · 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.

00
2 0 7 213
Log in or sign up to continue

Replies

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 Bob 
 

Thanks for the reply, as you said this approach has a drawback if we change $IO changed with in the process it self, and in our routines we are  generating files after accepting the input.

Thanks

Paras

On Windows with cterm.exe you can write special terminal scripts.

on Linux, as I know terminal scripts not available, so, you just prepare the list of answers, if it's fixed. and just send it to stdin.

csession -U MYNAMESPACE ^MyRoutine < myanswers.txt

or

cat myanswers.txt | csession -U MYNAMESPACE ^MyRoutine

 

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

The Job way also possible just a bit more complex.

Yes, I agree, to accomplish the same via JOB is complex but I am unable to explore / find another way within cache to achieve the same.  If you have other suggestion that can help me in this direction then please do let me know.

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"