i have a main python program that calls a security program. I want to return security data to pass data values to the caller program for downstream processing
Does the security program have an API, or a feature that outputs what you need as a service, or in a file?
One way is to have the main progtram capture the output of the security program. In the security program print the data you want to pass back.
The python subprocess.run()
can do the running and capturing. See its documentation.
I have many print statements to verify the security codes are there. Once I have completed testing, I will remove the print statements
The security routine validates user signon and division code.
If validated the code opens the main transaction. If validation fails, the logon screen remains.
I want to pass the signon and division code to the main program so I can store them as data fields to perform security test downstream.
Are you saying I can pass the print data to the main and store it as data variables?
nothing that sophisticated,
The called program is security routine validates user signon and division code.
If validated the code opens the main transaction. If validation fails, the logon screen remains.
I want to pass the signon and division code to the main program so I can store them as data fields to perform security test downstream.
You would need to parse the stdout of the security program to exact the data you need. To make the parsing easy you will need to decide on the format of the output. It could be lines that are key:value
for example.
I will definitely try that.
I am surprised that Python lacks the ability to provide direct access of data variables from a called program to the caller
Thank you for your suggestions, I will definitely test
Python supports file IO in multiple formats, stdin & stdout pipes, many server/client protocols, sockets, mqtt etc., calling functions and getting outputs from .so and .dlls, and many other protocols.
But whether or not Python can get direct access to the data variables of some arbitrary security program (without using pen testing tools or otherwise hacking it), depends on that program’s UI and API.
The security program is a python program (call pgm)that is being called by another python program(caller pgm). I want to have access to the logon information in the call prm
Why do you have two programs? Can’t you do all the logic in one program? It seems two programs is making the task hard for you.
Can’t the called function just return
the values as usual?
What are “pgm” and “prm”?
I am starting to agree with you. My concept was to keep the main calling program lean with the ability to call many other python programs.
I was hoping to use the concept of called variables available to the caller program in many instances. If this cannot be accomplished it seems I will have a single super huge program
My apologies, prm is a misspell for pgm
The called program is called security_test01.py
The caller program is called dashboard.py
Both are in the same project library and windows folder structure
And what is “pgm”? And what about my first question?
To be clear–you can certainly pass values between different modules, within the same program. A program can be made up of many different modules (i.e. different python files)
It sounded like you wanted to have two programs running in separate processes that communicated with each other. That’s not necessary and certainly not simpler–you can just import one module in the other and call the methods you need.
Based on what I have read, I should be able to return data variables from a called program. I have not found anything to help except returning a print using the PIPE statements
Any examples showing returning data values would be greatly
What are you actually trying to achieve? It doesn’t seem entirely clear that writing this as 2 programs makes much sense.
The long term is to have a main caller program that has many callable programs. Imagine a menu with all types of food, but each food is a callable program.
Instead of having one huge hard to manage program, one menu program with many callable programs with issues being in the callable program
moving to separate programs adds additional complexity and doesn’t actually remove the complexity of organising your code. it just scatters that code around.
If your convinced you want to try this though then an easy way of getting output back from your sub programs is using a temp file.
call your sub process and pass the temp file as an argument
my_program arg1 arg2 arg3 --output-file /tmp/fdslkfjdse5.json
when the process ends read the temp file.
Yeah, you can do this, but it’s almost definitely not the simplest or easiest way to design this system. A huge program is not harder to manage if it’s designed in a reasonable way.
Perhaps you want to use sub-commands for the different options?