尝试使用Python通过Popen

尝试使用Python通过Popen

本文介绍了尝试使用Python通过Popen()发送EOF信号(Ctrl + D)信号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让Python通过Popen()发送EOF信号( + ).不幸的是,我在类似* nix的系统上找不到Popen()信号的任何参考.这里有人知道如何发送这样的EOF信号吗?另外,是否有任何可以接收的可接受信号的参考?

I'm trying to get Python to send the EOF signal (+) 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?

推荐答案

EOF并不是您可以提出的信号,它是每个通道的特殊情况. (按 + 表示交互式输入结束实际上是终端驱动程序的功能.当在新行的开头按此组合键时,终端驱动程序告诉OS内核输入流上没有其他可用的输入.)

EOF isn't really a signal that you can raise, it's a per-channel exceptional condition. (Pressing + 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.)

通常,在管道上向EOF发出信号的正确方法是关闭写通道.假设您使用stdin=PIPE创建了Popen对象,看起来您应该能够做到这一点.

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.

这篇关于尝试使用Python通过Popen()发送EOF信号(Ctrl + D)信号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 18:28