1

One simple question: I have Linux process ID, which is 3789. How can I send 'ENTER' to this process by using Python?

  • Is the process waiting on reading stdin? Is it connected to a terminal, a GUI? Was it started by the Python program? – cdarke Sep 10 '15 at 07:45
  • Yes, the process is waiting for 'ENTER'. It was started by Python script, and it is connected to terminal. – user5311867 Sep 10 '15 at 07:48
  • You need to run the program using a pipe, preferably using `subprocess.Popen`. Just send it a `'\n'`. Or are you asking for a process that is currently running? – cdarke Sep 10 '15 at 07:50
  • also check out `pexpect`. – gauteh Sep 10 '15 at 07:50

1 Answers1

0

You are able to do such thing but with proc name using Python subprocess but not with PID.

from subprocess import Popen, PIPE
p = Popen(['proc_name', filePath], stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True)
p.stdin.print('\n') # sends Enter into process
wolendranh
  • 4,202
  • 1
  • 28
  • 37