问题
I'm trying to get Python to send the EOF
signal (Ctrl+D) via Popen()
. Unfortunately, I can't find any kind of reference for Popen()
signals on *nix-like systems. Does anyone here know how to send an EOF
signal like this? Also, is there any reference of acceptable signals to be sent?
回答1:
EOF
isn't really a signal that you can raise, it's a per-channel exceptional condition. (Pressing Ctrl+D to signal end of interactive input is actually a function of the terminal driver. When you press this key combination at the beginning of a new line, the terminal driver tells the OS kernel that there's no further input available on the input stream.)
Generally, the correct way to signal EOF
on a pipe is to close the write channel. Assuming that you created the Popen object with stdin=PIPE
, it looks like you should be able to do this.
来源:https://stackoverflow.com/questions/17678620/trying-to-send-an-eof-signal-ctrld-signal-using-python-via-popen