I am trying to write a python script which will execute a bash command line program for me. This program asks for user input twice, and I want my script to automatically enter "1" each time.
I've heard of something like this:
os.system("program < prepared_input")
How do I write prepared_input? Thanks.
Create file with two lines:
1
1
And use read in the bash script to get the input:
Demo:
$ cat abc
1
1
$ cat so.sh
#!/bin/bash
read data
echo "You entered $data"
read data
echo "Now you entered $data"
$ bash so.sh <abc
You entered 1
Now you entered 1
Python :
>>> import os
>>> os.system("bash so.sh < abc")
You entered 1
Now you entered 1
0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With