Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write EOF to STDIN popen in python

I have the following command run through popen:

p = subprocess.popen(["/usr/bin/whiptail", "--title", "\"Progress\"", "--gauge", "\"\"", "6", "50", "0"], stdout=subprocess.PIPE, stding=subprocess.PIPE)

To stop the whiptail command from running I need to send EOF to stdin.

How do I send EOF to stdin in Python ?

or I just call p.terminate()

like image 369
gudge Avatar asked Aug 30 '15 16:08

gudge


People also ask

What is subprocess popen ()?

The subprocess module defines one class, Popen and a few wrapper functions that use that class. The constructor for Popen takes arguments to set up the new process so the parent can communicate with it via pipes. It provides all of the functionality of the other modules and functions it replaces, and more.

What is Python Popen?

Python method popen() opens a pipe to or from command. The return value is an open file object connected to the pipe, which can be read or written depending on whether mode is 'r' (default) or 'w'. The bufsize argument has the same meaning as in open() function.

What does Popen communicate return?

Popen Function The popen() function will execute the command supplied by the string command. The function should return a pointer to a stream that may be used to read from or write to the pipe while also creating a pipe between the calling application and the executed command.


1 Answers

What you need is to close the file used as standard input for your script.

So in your case it's p.stdin.close().

like image 135
letitbee Avatar answered Oct 12 '22 11:10

letitbee