[英]Return the results of running a program in realtime using Node.js?
Is there a way to run a program (for example: tcpdump) and every time it shows something through the console, from nodejs capture it and return the result to print in an html?有没有办法运行一个程序(例如:tcpdump),每次它通过控制台显示一些东西时,从 nodejs 捕获它并返回结果以在 html 中打印? no need to save it, keep it in real time.
无需保存,实时保存。
My idea is that a program can be executed and while it is running and showing things in the console, they can be sent to the html where you can progressively see all the results of the program's execution.我的想法是一个程序可以被执行,当它运行并在控制台中显示内容时,它们可以被发送到 html,在那里您可以逐步查看程序执行的所有结果。
Thanks for help.感谢帮助。
I think using socket io is a good solution, check there get started tutorial我认为使用套接字 io 是一个很好的解决方案,请查看入门教程
No need to do anything like "capturing output" in Node.js.无需在 Node.js 中执行“捕获输出”之类的操作。 You can use the heredoc available in almost every shell.
您可以使用几乎所有 shell 中可用的 heredoc。 The heredoc, in the most basic sense, redirects the output of a command to a file.
从最基本的意义上说,heredoc 将命令的 output 重定向到文件。 In your example, if you use
tcpdump
, here's what you'd do:在您的示例中,如果您使用
tcpdump
,请执行以下操作:
$ tcpdump [options] >> file.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.