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.