如何将此命令的实时流输出保存到在 while 循环中逐行运行的变量/连接?就像是:
netvalue <-system("tcpdump -A -i eth0 port 80 | grep foo")
while(T) {
...
nvar <- netvalue + othervalue
...
}
或者
In a terminal:
$ tcpdump ... | grep --line-buffered [myterm] > fifofile
Then in R:
> con = fifo("fifofile", "r")
> open(con, "r")
> con
description class mode text opened can read
"fifo" "fifo" "r" "text" "opened" "yes"
can write
"no"
> readLines(con, n = 1)
> [myterm]
.. but it only works sometimes, and often
for a limited term, when it fails always returning:
> character(0)
在 readLines(con, n = -1) 中使用“-1”参数清除整个 fifofile 似乎会持续地终止连接!?