BASH:错误消息未重定向到文件 [英] BASH: error message does not get redirected to file

查看:84
本文介绍了BASH:错误消息未重定向到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个bash脚本,可以简单地调用不同的调用,并将stdout和stderr输出重定向到不同的文件.

I have a bash script that simply calls different calls and redirect stdout and stderr outputs to different files.

我已经做到了:

command 1> datafile 2>> errorfile

但是,如果命令错误(例如,错误的用户名和密码组合作为参数给出),则错误消息不会重定向到错误文件.运行此脚本时,我仍然在屏幕上看到错误消息.例如,错误消息表明我提供的用户名和密码组合错误.

However, when the command is erroneous (e.g. wrong username and password combination given as arguments), the error message does not get redirected to the errorfile. I still see the error message on my screen when I run this script. For instance, the error message indicates that I provided a wrong combination of username and password.

我做错了什么? 我以为我应该在屏幕上看不到任何输出,因为我正在将stdout和stderr都重定向到文件.

What am I doing wrong? I thought I should see no output on screen because I'm redirecting both stdout and stderr to files.

推荐答案

也许程序不是在写stderr,而是直接打开/dev/tty与用户通信?在进行密码交互时,这种方法相当普遍:软件希望确保即使有任何重定向,密码提示也会通过"用户.

Perhaps the program isn't writing to stderr, but directly opening /dev/tty to communicate with the user? This approach is fairly common when it comes to password interaction: software wants to make sure password prompts get "through" to the user despite any redirections.

在这种情况下,您需要使用伪终端欺骗来安排输出以最终存储在文件中.

If this is the case, you need pseudo-terminal trickery to arrange output to end up in a file.

如果没有该软件的源代码,则可以使用strace/truss找出程序的实际作用.

If you don't have the source of the software, you can use strace/truss to find out what the program is really doing.

这篇关于BASH:错误消息未重定向到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆