LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 898|回复: 5

bash -i 重定向问题

[复制链接]
发表于 2006-2-20 10:28:41 | 显示全部楼层 |阅读模式
在正常的用户提示符下执行bash -i|tee /tmp/1.log,可以在不影响正常的命令运行交互的情况下,把所有执行命令的结果输出到/tmp/1.log。本人希望能能够记录所有的交互的过程,于是在正常的用户提示符下执行bash -i 2>&1|tee /tmp/1.log,但是只能达到部分的效果,即可以记录交互过程,但却出现了意想不到的结果,无法执行vi,su,ssh...,错误提示如下所列组合:
Vim: 注意: 输出不是终端(屏幕)
bash: [13848: 2] tcsetattr: 无效的参数。
不知可有透明的bash语句,可以实现记录所有的交互的过程,但却不影响bash命令行的使用。
发表于 2006-2-20 12:43:01 | 显示全部楼层
right, because you pipe it to a log file instead of the terminal output. Try script cmd, other than that, I am not aware of anything else.
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-2-20 14:00:40 | 显示全部楼层
bash -i|tee /tmp/1.log不影响命令执行,但是无法记录标准输入,
bash -i 2>&1|tee /tmp/1.log可以记录标准输入,却影响部分命令执行。2>&1只不过把错误输出重定向到标准输出,为什么会有以上的效果和的区别呢?请版主和其他高手分析指点。
回复 支持 反对

使用道具 举报

发表于 2006-2-20 14:54:03 | 显示全部楼层
Post by yongjian
right, because you pipe it to a log file instead of the terminal output. Try script cmd, other than that, I am not aware of anything else.

......
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-2-20 15:31:36 | 显示全部楼层
but,run "man tee",we can get infomation as "tee - read from standard input and write to standard output and files"。The pipe write to standard output and log files,not only log file。If script cmd can do,who can show it。
回复 支持 反对

使用道具 举报

发表于 2006-2-21 04:00:22 | 显示全部楼层
but it did redirect the output to a NON-TTY device even though it dup it to std out. And because it is a pipe, vi, su, etc those cmds just wouldn't accept pipe. if you do
  1. ls -la /dev/fd
复制代码
you will see normally file descriptors will link to your tty device, pipe and "><" symbols will change that no matter what. script cmd is different, not sure what technology it uses, but it will not redirect fds to something else. It probably just simply grab whatever prints out to the terminal screen.  To use script, pls see the man page. Its simple.
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表