分页: 1 / 1

如何将一命令标准错误输出到变量

发表于 : 2015-09-24 19:08
自由建客

代码: 全选

Second=$(dialog --nocancel --rangebox "$TextText" 2 40 1 30 3)
这样不对,因为 dialog 其实是用标准错误输出值的,怎么破?

Re: 如何将一命令标准错误输出到变量

发表于 : 2015-09-25 13:14
astolia
重定个向 2>&1

Re: 如何将一命令标准错误输出到变量

发表于 : 2015-09-25 14:06
Russell_D_Lee
由于使用$()可以把标准输出赋给变量,而我们可以重定向标准错误输出到标准输出,并且丢弃原标准输出的内容。
所以我只能想到:

代码: 全选

Second=$(dialog --nocancel --rangebox "$TextText" 2 40 1 30 3 2>&1 1>/dev/null)
不知道是否有更优雅的方法。

Re: 如何将一命令标准错误输出到变量

发表于 : 2015-09-25 16:11
susbarbatus
Some widgets, e.g., checklist, will write text to dialog's output. Normally that is the standard error, but there are options for changing
this: "--output-fd", "--stderr" and "--stdout". No text is written if the Cancel button (or ESC) is pressed; dialog exits immediately in
that case.

Re: 如何将一命令标准错误输出到变量

发表于 : 2015-09-25 18:33
自由建客
Russell_D_Lee 写了:由于使用$()可以把标准输出赋给变量,而我们可以重定向标准错误输出到标准输出,并且丢弃原标准输出的内容。
所以我只能想到:

代码: 全选

Second=$(dialog --nocancel --rangebox "$TextText" 2 40 1 30 3 2>&1 1>/dev/null)
不知道是否有更优雅的方法。
嗯,就是这样。