1

I am running some bash commands via python os.system('/vt -start ./home/mydb ./home/images/image-001-053.png 2>&1 | tee ./ results.txt >/dev/pts/2'). This is a command which can be run on terminal with tty=/dev/pts/2.

After running the command , the output of bash terminal is saved in a file (results.txt) and later I should read the file. The problem is that after running the command, I need to press keyboard Enter key manually to run the next command in the same terminal with tty number 2, python is not forcing '\n' to return to command line again.

Do you have any suggestion? How can I add a command which simulates keyboard Enter key on the terminal?

sc241
  • 95
  • 1
    What is the specific command? Generally, you can either tell the program not to prompt for input, or you can pipe your input directly into the command. So if your command was read (which requires you to press enter), then you could do echo | read from bash to get around that. expect is a more advanced tool for this. – habs Apr 13 '18 at 20:26
  • 2
    I'm not sure if I can solve this without an MCVE. Can you try to give one? – habs Apr 13 '18 at 20:27
  • 1
    Whatever it should do, don't use os.system() anymore. Deprecated and terribly, terribly outdated. – Jacob Vlijm Apr 13 '18 at 21:03
  • @Harry this is my command ./vt -start ./home/mydb ./home/images/image-001-053.png 2>&1 | tee ./ results.txt >/dev/pts/2 – sc241 Apr 13 '18 at 21:09
  • @JacobVlijm What should I use instead? I need to run the command via bash terminal (which is two different bash terminals), one is >/dev/pts/2 and the other >/dev/pts/18. One acts as client side – sc241 Apr 13 '18 at 21:11
  • 1
    @sc241 depends on the situation, I can't see what the python code should do exactly, but most likely either subprocess.call(), subprocess.Popen() or subprocess.check_output(). – Jacob Vlijm Apr 13 '18 at 21:15
  • @sc241 Can you edit your question to include an MCVE? I want to help but I can't until I have that here. – habs Apr 13 '18 at 21:22
  • @Harry, sorry i am new here, sure. i will try – sc241 Apr 13 '18 at 21:34
  • @JacobVlijm OP's situation is explained in this question – you're welcome to change or extend my answer there! – dessert Apr 14 '18 at 05:46

0 Answers0