亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区
Chinaunix
標(biāo)題:
如何讀取一個(gè)持續(xù)輸出內(nèi)容程序的內(nèi)容
[打印本頁]
作者:
forgaoqiang
時(shí)間:
2014-02-17 17:31
標(biāo)題:
如何讀取一個(gè)持續(xù)輸出內(nèi)容程序的內(nèi)容
做個(gè)簡(jiǎn)單的例子,比如這個(gè)命令集合
ping www.chinaunix.com -c 100
復(fù)制代碼
我希望在這個(gè)命令每一次輸出(到標(biāo)準(zhǔn)輸出)的時(shí)候都賦值給一個(gè)變量,而不等待整個(gè)ping命令執(zhí)行完畢再獲取ping命令的輸出
不知道有什么辦法可以實(shí)現(xiàn)呢~
作者:
runintostar
時(shí)間:
2014-02-17 18:09
回復(fù)
1#
forgaoqiang
看看這樣行么?
bash-3.2$ ./test.sh
Mon Feb 17 17:34:47 CST 2014
PING 10.20.39.145 (10.20.39.145) 56(84) bytes of data.
Mon Feb 17 17:34:47 CST 2014
64 bytes from 10.20.39.145: icmp_seq=1 ttl=124 time=3.03 ms
Mon Feb 17 17:34:48 CST 2014
64 bytes from 10.20.39.145: icmp_seq=2 ttl=124 time=1.99 ms
Mon Feb 17 17:34:49 CST 2014
64 bytes from 10.20.39.145: icmp_seq=3 ttl=124 time=1.79 ms
Mon Feb 17 17:34:50 CST 2014
64 bytes from 10.20.39.145: icmp_seq=4 ttl=124 time=1.81 ms
Mon Feb 17 17:34:51 CST 2014
64 bytes from 10.20.39.145: icmp_seq=5 ttl=124 time=1.76 ms
Mon Feb 17 17:34:52 CST 2014
64 bytes from 10.20.39.145: icmp_seq=6 ttl=124 time=1.91 ms
Mon Feb 17 17:34:53 CST 2014
64 bytes from 10.20.39.145: icmp_seq=7 ttl=124 time=4.83 ms
Mon Feb 17 17:34:54 CST 2014
64 bytes from 10.20.39.145: icmp_seq=8 ttl=124 time=1.80 ms
Mon Feb 17 17:34:55 CST 2014
64 bytes from 10.20.39.145: icmp_seq=9 ttl=124 time=1.58 ms
Mon Feb 17 17:34:56 CST 2014
64 bytes from 10.20.39.145: icmp_seq=10 ttl=124 time=1.69 ms
bash-3.2$ cat test.sh
#!/bin/sh
mkfifo tmpfile
exec 6<>tmpfile
ping -c 10 10.20.39.145>&6 &
i=0
while [ $i -le 10 ]
do
read a<&6
date
echo $a
i=`expr $i + 1`
done
exec 6>&-
rm tmpfile
復(fù)制代碼
作者:
forgaoqiang
時(shí)間:
2014-02-17 18:28
{:3_188:}
非常感謝 提供的FIFO文件的思路太棒了 我試了管道、重定向、信號(hào)機(jī)制 都沒有成功 居然沒有想到還有這一招~
不知道怎么感謝你 哈哈 你要是有百度賬號(hào)的話 請(qǐng)回答下這個(gè)問題吧:
http://zhidao.baidu.com/question/1109861636581202219.html
200財(cái)富算是小小的回禮吧~
回復(fù)
2#
runintostar
作者:
runintostar
時(shí)間:
2014-02-17 19:20
回復(fù)
3#
forgaoqiang
hehe,能幫到你就好,我還沒用過百度那個(gè),不過剛才去回答了,就當(dāng)玩一下,哈哈
作者:
elu_ligao
時(shí)間:
2014-02-17 22:34
good idea, thanks for sharing
作者:
liion631818
時(shí)間:
2014-02-18 09:33
好像下面那個(gè)人給的答案也滿足吧,都是重定向的讀
ping www.baidu.com -c 100 | while read -r line; do date; echo $line; done
復(fù)制代碼
作者:
forgaoqiang
時(shí)間:
2014-02-18 15:35
恩 對(duì)于ping是這樣的 我舉例子不恰當(dāng)~。。。。
回復(fù)
6#
liion631818
歡迎光臨 Chinaunix (http://72891.cn/)
Powered by Discuz! X3.2