I am trying to find a way to invoke an interactive command-line program so that it enters data both directly from the keyboard and from a named pipe. My goal is to make this work with MATLAB, but I think Bash works the same way as the example. Therefore, the idea is to start Bash, and as soon as it starts, I can enter commands, use the up arrow for history, etc., and also send commands to the named pipe. I looked around and did this for several days, but none of what I have tried so far has worked perfectly correctly.
For example, there is a useful thread at https://serverfault.com/questions/171095/how-do-i-join-two-named-pipes-into-single-input-stream-in-linux that suggests doing something like this:
mkfifo alt_in
(tail -f alt_in & cat) | bash
This is almost what I'm looking for, except if you are trying to use backspace or arrow keys, it does not work correctly. (I think this is because it catintercepts keystrokes that are usually handled by the readline library in bash?) Does anyone have any other suggestions?
Ultimately, I would like to have a way to start the MATLAB process so that I can send commands to it from TextMate, but also interact with it in the terminal. I use MATLAB to work, but I don't really like its graphical interface or editor.
Edit December 19, 2010
! , . rlwrap, , TextMate, , ( ). expect unbuffer, , , , .
screen - , Terminal, start screen, start matlab -nodesktop, TextMate, , Matlab, screen -X ... TextMate. , , :
- 1024 `screen`; - -, , , , .
- , . , , ?
- Control-A - `screen`; , .
screen, , , , STDIN .., : TextMate . AppleScript, , , , . TextMate,
set input_command to do shell script "cat"
tell application "Terminal"
do script input_command in window 1
end tell
, MATLAB . ( "", MATLAB, .)
, . ; !