网站首页 > 基础教程 正文
如果用调用多个外部程序,而且希望第一个调用的返回内容做为第二个调用的参数。
该如何实现?
例如:
1、执行netstat -an;
2、把上面执行的结果用echo打印出来。
那么代码如下:
var cp = require("child_process"); var netstat = cp.spawn("netstat",["-an"]); var echo = cp.spawn("cmd",["echo"]); netstat.stdout.pipe(echo.stdin); echo.stdout.pipe(process.stdout);
代码解析:
1、dir和echo两个变量,分别是进行netsta和echo命令的执行。
2、netstat.stdout.pipe(echo.stdin)是将netstat的执行结果,通过管道输出给echo的输入。
3、再用echo.stdout.pipe(process.stdout)将echo的输出内容,以管道输出给process.stdout,以实现将内容打印到命令行中。
执行效果:
注意到与上方netstat -an执行结果的差异了吗?
异同在于,这里的输出,中间有空格。这是因为输出是实时进行的,netstat -an获得一个内容,会立刻传给echo,echo又通过process.stdout打印出来。
- 上一篇: 实践小记:Cypress
- 下一篇: 一次 Docker 容器内大量僵尸进程排查分析
猜你喜欢
- 2024-11-25 Deno 1.30 正式发布
- 2024-11-25 用 WasmEdge 和 Rust 在边缘云上构建高性能且安全的微服务
- 2024-11-25 通过浏览器工作台启动本地项目
- 2024-11-25 r2frida:基于Frida的远程进程安全检测和通信工具
- 2024-11-25 NPM 使用介绍
- 2024-11-25 使用Hexo在github上搭建静态博客
- 2024-11-25 Android动态调试(1)-Radare2和lldb
- 2024-11-25 Metasploit渗透测试之MSFvenom
- 2024-11-25 浅析CTF中的Node.js原型链污染
- 2024-11-25 首个SSRF漏洞开篇学习
- 06-09Socioeconomic growth goals high on meetings' agenda
- 06-09Cities Along Middle Reaches of Yangtze River Agree on 63 Cooperation Items
- 06-09Scientists to make flag flutter on moon
- 06-09CBN丨Foreign-funded institutions bullish on Chinese assets
- 06-09Full Text: Joint Statement between the People's Republic of China and the French Republic on Climate Change on the occasion of the Tenth Anniversary of the Paris Agreement
- 06-092022年底总结,温暖和激励自己的文案
- 06-09百度实时推送代码解决方案(百度实时推送工具)
- 06-09PHP漏洞之跨网站请求伪造(php跨站脚本攻击)
- 最近发表
-
- Socioeconomic growth goals high on meetings' agenda
- Cities Along Middle Reaches of Yangtze River Agree on 63 Cooperation Items
- Scientists to make flag flutter on moon
- CBN丨Foreign-funded institutions bullish on Chinese assets
- Full Text: Joint Statement between the People's Republic of China and the French Republic on Climate Change on the occasion of the Tenth Anniversary of the Paris Agreement
- 2022年底总结,温暖和激励自己的文案
- 百度实时推送代码解决方案(百度实时推送工具)
- PHP漏洞之跨网站请求伪造(php跨站脚本攻击)
- ThinkPHP后台入口地址查找(thinkphp build.php)
- PHP新手如何提高代码质量(php新手如何提高代码质量的方法)
- 标签列表
-
- jsp (69)
- gitpush (78)
- gitreset (66)
- python字典 (67)
- dockercp (63)
- gitclone命令 (63)
- dockersave (62)
- linux命令大全 (65)
- pythonif (86)
- location.href (69)
- dockerexec (65)
- tail-f (79)
- queryselectorall (63)
- location.search (79)
- bootstrap教程 (74)
- deletesql (62)
- linuxgzip (68)
- 字符串连接 (73)
- html标签 (69)
- c++初始化列表 (64)
- mysqlinnodbmyisam区别 (63)
- arraylistadd (66)
- mysqldatesub函数 (63)
- window10java环境变量设置 (66)
- c++虚函数和纯虚函数的区别 (66)