记录器为stdin stdout

时间:2011-09-02 15:24:41

标签: logging stdout stdin expect

要通过Emacs调试外部进程处理,我需要使用包装器来记录所有消息流。

因此Emacs将字符串发送到包装器stdin,包装器将其记录并发送到外部进程。然后返回外部进程发送输出,包装器登录并发送到Emacs。

我的期望知识很小所以我问问题。可能已经存在用于此目的的标准工具?

How to implement a stdin, stdout wrapper?不回答我的问题!!

2 个答案:

答案 0 :(得分:1)

我不了解情况。

交互是通过stdin和stdout完成的吗? T恤(1)http://unixhelp.ed.ac.uk/CGI/man-cgi?tee不符合您的所有要求吗?

答案 1 :(得分:1)

这个示例使我的魔杖以有限的形式(终端配置为规范模式,因此不允许使用某些字符代码):

#!/usr/bin/env expect

set in [open in.log w]
set out [open out.log w]

log_user 0
set stty_init {-echo}
exp_internal 1

# spawn sort
spawn /bin/prog
set proc_id $spawn_id

expect {
    -i $user_spawn_id -re . {
        puts -nonewline $in $expect_out(buffer)
        send -i $proc_id $expect_out(buffer)
        exp_continue
    } eof {
        send -i $proc_id \x04
        sleep 1
        send -i $proc_id \x04
        expect -i $proc_id -re . {
            puts -nonewline $out $expect_out(buffer)
            send_user $expect_out(buffer)
            exp_continue
        } eof { }
    }
    -i $proc_id -re . {
        puts -nonewline $out $expect_out(buffer)
        send_user $expect_out(buffer)
        exp_continue
    } eof { }
}
wait