Piping an interactive session to a file

后端 未结 4 1835
萌比男神i
萌比男神i 2020-12-05 12:33

I have made a toy interactive console program that is basically an interpreter:

$ myprogram
> this is user input
this is program output

相关标签:
4条回答
  • 2020-12-05 12:39

    script — make typescript of terminal session:

    script -c "myprogram" file.log
    

    The whole session will be logged to file.log

    0 讨论(0)
  • 2020-12-05 12:52

    An easy way is to use the script command. It just stores your whole terminal session. Run it with:

    script my-interactive-session.log program
    
    0 讨论(0)
  • 2020-12-05 13:01

    As two processes can't read the same input two tees are needed, one which reads terminal input and writes to program standard input and file.log another which reads program standard output and writes into terminal output and file.log:

    tee -a file.log | program | tee -a file.log
    
    0 讨论(0)
  • 2020-12-05 13:05

    The simpler form could be

    tee >(myprogram) | tee -a file.log
    

    If you want to prevent input being shown again to the screen:

    tee -a file.log | myprogram | tee -a file.log
    
    0 讨论(0)
提交回复
热议问题