0

I have a scenario where I need to start a python script in a new terminal. This script takes (waits for) user input at various steps in its execution. I want to automate it and provide all the sequence of inputs in a file. I tried the following but it doesn't work.

$ cat commands.txt
1\r
2\r
3\r

$ cat test.sh
#!/bin/bash
gnome-terminal -- python3 test.py 1<commands.txt

Can anyone please guide me on how to do this correctly ? I'm also not sure if using '\r' to separate each input in my commands.txt file is the right approach.

aynber
  • 22,380
  • 8
  • 50
  • 63
Jake
  • 16,329
  • 50
  • 126
  • 202
  • 1
    Maybe `gnome-terminal -e 'cat commands.txt | python3 test.py'` – Mark Setchell Oct 20 '22 at 19:32
  • 2
    maybe `gnome-terminal -e 'python3 test.py – Chris Dodd Oct 20 '22 at 21:49
  • 1
    @MarkSetchell That's a [useless `cat`](https://stackoverflow.com/questions/11710552/useless-use-of-cat); you are looking for `gnome-terminal -e 'python3 test.py < commands.txt'`. And no, `\r` doesn't do anything useful here, unless your Python program does something interesting with a literal backslash character followed by `r`. Just the newlines should suffice. – tripleee Oct 20 '22 at 23:46

0 Answers0