有没有一种方法可以将命令输出中的连续流发送到远程侦听器 [英] Is there a way to send a continuous stream from a command output to a remote listener
问题描述
我将netcat用于UNIX.
I'm using the netcat for unix.
当我运行 python script.py&logfile.txt
,它会被连续捕获.
when I run python script.py &> logfile.txt
, it gets captured continuously.
要远程复制此文件,我在侦听器(客户端)上尝试了 nc -l -p 8011
,在发送方(主机或服务器)上尝试了以下操作:
To replicate this remotely, I tried nc -l -p 8011
on the listener (client) and the following for the sender (host or server) :
-
python script.py&nc 127.0.0.1 8011
-
python script.py>nc 127.0.0.1 8011
-
nc 127.0.0.1 8011<python script.py
但是似乎没有任何效果.请帮忙.
But nothing seems to work. Please help.
推荐答案
这是您要的吗?
接收器:
nc -l 8011 >logfile.txt
发件人:
python script.py 2>&1 | nc 127.0.0.1 8011
确保首先运行接收器代码.
Make sure to run the receiver code first.
编辑:如果您不知道有很多不同版本的netcat ;它们都接受略有不同的参数(例如Debian上的 nc.traditional
希望 nc -l -p 1234
监听端口1234,而BSD nc
(例如OS X)只希望 nc -l 1234
和 ncat
可能引发一个有趣的错误,除非您的主机没有使用 -4
标志'不支持IPv6)-请阅读手册页,以了解您真正想要的选项组合.
EDIT: In case you're not aware there's a lot of different versions of netcat; they all accept slightly different arguments (e.g. nc.traditional
on Debian wants nc -l -p 1234
to listen on port 1234, whereas BSD nc
(e.g. OS X) just wants nc -l 1234
and ncat
may throw an interesting error unless you use the -4
flag if your host doesn't support IPv6) - read the man pages to find out what combination of options you actually want.
这篇关于有没有一种方法可以将命令输出中的连续流发送到远程侦听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!