使用bash,我怎么能管标准错误到另进程
it1352
帮助1人
问题说明
这是众所周知如何管一个进程的标准输出到另一个进程的标准输入:
It's well known how to pipe the standard ouput of a process into another processes standard input:
proc1 | proc2
但如果我要发送PROC1的标准误差PROC2离开标准输出将其当前位置?你可能会认为庆典
将有沿行的命令:
proc1 2| proc2
但是,唉,没有。有没有办法做到这一点?
But, alas, no. Is there any way to do this?
正确答案
#1
您可以使用下面的技巧来的交换的标准输出
和标准错误
。然后你只需使用常规的管道功能。
You can use the following trick to swap stdout
and stderr
. Then you just use the regular pipe functionality.
( proc1 3>&1 1>&2- 2>&3- ) | proc2
提供的标准输出
和标准错误
无论是在开始指向同一个地方,这会给你你需要什么
Provided stdout
and stderr
both pointed to the same place at the start, this will give you what you need.
它所做的:
3>&放大器; 1
创建它被设置为当前<$ C $一个新的文件句柄3
C> 1 (原标准输出)刚刚保存在某个地方吧。
1&GT;和2 -
套标准输出,以获得当前文件句柄2
(原标准错误),然后关闭2
。
2 - ;及3 -
套标准错误,以得到当前文件句柄3
(原标准输出),然后关闭3
。
3>&1
creates a new file handle3
which is set to the current1
(original stdout) just to save it somewhere.1>&2-
sets stdout to got to the current file handle2
(original stderr) then closes2
.2>&3-
sets stderr to got to the current file handle3
(original stdout) then closes3
.
这是有效的,你看到的排序swap命令:
It's effectively the swap command you see in sorting:
temp = value1;
value1 = value2;
value2 = temp;
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tanhcfefhj
系列文章
更多
同类精品
更多
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
检查邮件是否发送成功
it1352 07-25 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
Android微调工具-删除当前选择
it1352 06-20 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20 -
希伯来语的空格句子标记化错误
it1352 06-22