Question
· 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
Discussion (3)1
Log in or sign up to continue

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