关闭标准输入而不关闭OPEN_BOTH管道上的标准输出

问题描述

我一直在尝试将fzfGuile编程语言集成在一起,但是我一直在努力寻找如何在不关闭stdout的情况下关闭输入输出管道的stdin。

这是我想在python中做的一个例子:

import subprocess

proc = subprocess.Popen(
    "fzf",encoding="UTF-8",stdin=subprocess.PIPE,# stdin is piped for fzf to get the choices list
    stdout=subprocess.PIPE,# stdout is also piped so the program can read what was chosen
    # stderr is not piped,since fzf's interface is drawn there
)

# write to fzf's stdin and close it
proc.stdin.write("Choice 1\nChoice 2")
proc.stdin.close() # stdin is closed but stdout is still open

# read fzf's stdout,which is where the chosen element is returned
output = proc.stdout.read()

如您所见,我首先使用stdin,然后将控件转到fzf,它将把用户选择的内容写入stdout。

这是我(失败)尝试在Guile上重新创建它的方法:

(use-modules (ice-9 popen)
             (ice-9 rdelim))

(define (fzf-example)
  (let ((port (open-pipe* OPEN_BOTH "fzf")))
    (display "Choice 1\nChoice 2" port) ;; write to fzf's stdin
    (close-pipe port) ;; closes fzf's both stdin and stdout - not what I wanted
    (read-line port) ;; would probably return what was output by fzf but the stdout was closed on the previous line
    ))

我一直在寻找Guile Reference Manual上的答案,但那里也找不到任何东西-pipeline命令很相似,但并不是我想要的。但我可能错过了一些东西。我还发现了this question,但是它只帮助我找到了一种写到stdin的方法。

注意:这是我第二次尝试写这个问题。我以前的尝试没有一个很好的例子,这个问题有点含糊,所以在这里我要再提出一个。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...