我正在尝试通过发送一系列命令并捕获输出来测试特定的聊天程序。
我该如何传递:
sleep 2
echo test
sleep 2
echo test1
我尝试过以下方法:
(sleep 2; echo test; sleep 2; echo test1) | python3 test.py
但是它只打印了第一个部分,而对于第二个部分,我什么也没有得到。相反,它进入了一个无限循环。
Python程序代码如下:
import sys, select
while True:
socket_list = [sys.stdin]
read_sockets, write_sockets, error_sockets = select.select(socket_list, [], [])
for sock in read_sockets:
message = sys.stdin.readline()
sys.stdout.write("> %s: ")
sys.stdout.flush()
我应该提到,这不是完整的程序,而是帮助重新创建完全相同效果的部分。
{ sleep 2; echo test; sleep 2; echo test1 }
,并且将其重定向到Python而不是管道中? - jesse_bdate +%s; (sleep 2; echo test; sleep 2; echo test1) | perl -pe '$_=time()." ".$_'
对我来说显示了两个test
字符串和两秒的延迟。 - thrig