When work with Emacs comint I need logger for stdin/stdout process
interaction.
So I change name of calling program in Emacs
and that logger/script call original command and log
stdin and stdout to files.
I try write expect script:
#!/usr/bin/env expect
set in [open in.log w]
set out [open out.log w]
log_user 0
spawn sort
set proc_id $spawn_id
stty -echo
expect {
-i $user_spawn_id -re . {
puts -nonewline $in $expect_out(buffer)
send -i $proc_id $expect_out(buffer)
exp_continue
} eof { }
-i $proc_id -re . {
puts -nonewline $out $expect_out(buffer)
send_user $expect_out(buffer)
exp_continue
} eof { }
}
expect -i $proc_id -re . {
puts -nonewline $out $expect_out(buffer)
send_user $expect_out(buffer)
exp_continue
} eof { }
close $in
close $out
but this is my first serious Expect script and it works bad:
$ printf 'b\nquit\na\n' | ./logger.exp; \
printf '\n===in===\n'; cat in.log; \
printf '\n===out===\n'; cat out.log
b
quit
a
C-c C-c # I type C-c
===in===
b
quit
a
===out===
b
quit # Why not sorted???
a
Are there any program that do this job or please help fix this script.