Written by

Question Bryan Cass · Nov 10, 2023

Python: How to pass parameter to Cache routine and receive back response

I have an existing Python script that opens a child session using the pexpect library. But currently all it does is send hard-coded commands to the Cache process and expect a hard-coded response back in order to continue in the script.

I would like to run a Cache routine from the script, pass in a parameter, and wait for a response that will be different every time (a date, in this case). So the call would be something like D $$Tag^Routine(parameter) and wait for the routine to complete and return the response.

Is there a way to do this? I am looking at the Python subprocess module, but not very familiar with Python in general. An example script to help me get started would be ideal, thank you!

Bryan

Product version: IRIS 2022.1
$ZV: IRIS for UNIX (Red Hat Enterprise Linux 8 for x86-64) 2022.1.2 (Build 574_0_2241 8U) Thu Apr 20 2023 17:02:57 EDT

Comments

Robert Cemper · Nov 11, 2023

You may take a look at my example.  
You can run ObjectScript as in a terminal and receive a reply.
But it is invoked out of Python. external  or embedded

0
Bryan Cass · Nov 14, 2023

Thank you, Robert. Unfortunately, the sysadmin that hosts the Cache system does not allow NativeAPI to run from Python. It's a healthcare application and they are very particular about allowing outside access to the data or code.

So I have to spawn a process that logs into the Cache application as if it were an interactive user (which is how the pexpect library is used), then run my routine and receive back the output. Is there a way to do this with the pexpect or expect libraries? Or is there another library that will receive any response from a routine call rather than a hard-coded response?

The alternative to this, which I'm trying to avoid, is to have the Cache routine open a file and write its response into the file, then close the file.  Then the Python script would somehow wait for the file to appear, open the file, read the response, then close and delete the file.

Thanks!
Bryan

0
Bryan Cass · Dec 14, 2023

I figured out a way to do it.  Passing parameters in is not a problem. So I wrote the Cache routine to receive multiple parameters and then pass back a TRUE or FALSE response that the script can then act on.

I never did find a way to receive a random response from the Cache routine using the pexpect library.

0