How to get a python script to send values to another python program that is waiting for user input

I am using Robot Framework in Eclipse IDE to test functions inside an extracted python program called ‘GDX.py’ One of the functions is prompting with:

x = input(“Select one device:”)

My Robot Framework Test Case does the following:

usb_smoke_test_1_GDX_TMP
[Tags] usb_smoke
Log Smoke test verifies we can connect a USB GDX-TMP sensor
usbportfeed.Choose Usb ${port_1_gdx_tmp}
open usb
check_usb_temp_probe_KW
close

The above is a smoke test to select a known serial numbered Temperature probe off a known USB port. It calls an external python file called usbportfeed that takes the variable ‘port_1_gdx_tmp’. That external usbportfeed Python script is as follows:

import pynput
from pynput.keyboard import Key, Controller
keyboard = Controller()

def choose_usb(portvalue):
keyboard.type(portvalue)
keyboard.press(Key.enter)
keyboard.release(Key.enter)

This usbportfeed simulates keyboard presses to the console so that the function inside GDX.py that is using the input() statement can get it’s input and make the selection to simulate a user doing it with the keyboard.

This all works fine when I run the following command line and passes the smoke test:

robot -t usb_smoke_test_1_GDX_TMP .\GDTest\GoDirectSuite1.robot

However, once I included a Jenkins plugin to Eclipse and get batch files to run the same command line. I get “EOFError: EOF when reading a line”

What I think is happening is the standard output is not directed to the right place due to Jenkins. Does anybody know how to get the standard output to send properly. I need the output of that usbportfeed to send the output there so the ‘input()’ command in the other program is satisfied.

IN CONCLUSION:
I want Python file A to feed it’s output to a prompt coming from Python file B (when Jenkins executes the batch file)

Hate to say it @MelRaymond but that is WAAAY outside the realm of a forum for beginner coder questions. I think I would literally need your board to try it out. But, you might be able to use:

https://docs.python.org/2/library/subprocess.html

And possibly:

I was afraid that might be the case. I am fairly new to Python. There is a lot piled on top Python here with my Eclipse IDE, Robot Framework, and Jenkins. I can’t seem to get an answer from anywhere unfortunately, and I have tried using examples from other sites using that “subprocess” as an import to try and rig some sort of standard ouput and input pipe that will do the trick. One would think sending output from python program A to the input of python program B would be easy. It is if not running third party software I guess, because I had it working until I installed the Jenkins plugin into Eclipse and got Jenkins setup to run it automatically. I have no idea how to use these pipes or why Jenkins would mess up my very same command line to execute my test cases via batch file. I’ll take a look at your link you sent and I really appreciate your feedback. It’s more than I get from stackoverflow. If anyone else has any ideas or experience they want to share on piping output from one python file to another (under Jenkins), I would really be grateful (especially if I can get this working). BTW: I’m using Python 3.7.3

In the end, if I can’t get this piping working I may just settle for having our developers add some argument variables to any of the “def” inside gdx.py so whenever the argument is being used, then it will bypass the “input()” statements and just set the variable so I can move on.

I mean, normally on a unix system you’d just pipe it:

python prog1.py | python prog2.py

Done. But it sounds like you’re doing something way more complicated than that since this is across devices and needs…network code?

Here’s what I suggest, you need a spike. A spike is where you solve one problem in a tiny small model without a lot of tools. Right now you got a mountain of random things you’re using that have nothing to do with “get program A to talk to program B”.

What you need to do is create a separate CLEAN project that is like 2 little Python scripts literally named progA.py and progB.py and then work out how they will talk to each other. Check out ZeroMQ, Subprocess, plain old HTTP requests, and work out just the protocol of how they talk. Protobufs is another option:

The number 1 thing you should NOT do is invent your own protocol. Every hardware engineer tries to do that and it’s a security disaster of epic proportions. Use something established like ZeroMQ or Protobufs and then stick with it. Also, don’t use UDP. Every idiot thinks UDP is easier and faster and then 5 years later they’ve ended up reinventing a terrible TCP with UDP.

Once you have your spike working, you can turn this into a module that you then import into your original project and get everything working. But, trying to work this out inside your current project is just making it more difficult.