我想从shell(bash)读取stdin,并将stdout发送到shell以及重定向文件。我尝试以下:Python - 我如何从shell读取stdin,并将stdout发送到shell和文件
$ cat test.py
#!/usr/bin/python
val = raw_input("enter val: ")
print val
$ ./test.py | tee out
testing
enter val: testing
$ cat out
enter val: testing
出于某种原因,该提示的raw_input打印完成后I型我的输入,这意味着不能看到提示为I型。用bash脚本,我可以得到类似于工作的东西。
$ cat test.sh
#!/bin/bash
echo "enter val: "
read val
echo $val
$ ./test.sh | tee out
enter val: testing
testing
$ cat out
enter val: testing
我不认为这是问题。我尝试了与OP相同的内容,但使用'print'输出提示,结果相同。 – senderle 2011-06-02 18:54:05
好吧,它只是没有冲洗你看到相同的症状 - 请参阅tMCs回答 – rlawson 2011-06-02 19:00:51
你是对的,我现在明白了。 – senderle 2011-06-02 19:01:49