0

I'm trying to create a bash script that can write values into a separate python shell that is constantly running, which is expecting user input, then read back the returned value into my bash script.

Backstory: I can't just call the python script from directly within the bash script as the python script is constantly running, with a fairly long initialization which I don't want to do each time I call it.

So it can be condensed into two questions;

  • How can I write to python 'user input' programmatically within bash
  • How can I reliably read what is returned from the python script into a bash variable (it can be printed out and returned however I like)

I am familiar with bash basics, but I am still fairly new to it. I am guessing it has something to do with reading/writing to stderr, stdout, or stdin?

Any advice given would be very useful, thanks.

2
  • 1
    If you can get python to listen on a set port you should be able to send requests to there from bash Commented Aug 22, 2019 at 8:59
  • What have you tried so far? Commented Aug 22, 2019 at 9:03

1 Answer 1

1

After further searching I found that sockets are definitely the way to go. The example I found here worked perfectly: Basic Python client socket example

Thank you Shardj for the suggestion

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.