Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3445042
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:59:32+00:00 2026-05-18T08:59:32+00:00

I’m trying to find a way to invoke an interactive command-line program so that

  • 0

I’m trying to find a way to invoke an interactive command-line program so that it takes input both directly from the keyboard and also from a named pipe. My goal is to get this working with MATLAB, but I think Bash works just as well as an example. So the idea is to start Bash and once it’s running I can type commands, use up arrow for history, etc, and also send commands to a named pipe. I’ve been looking around and fiddling with this for a few days, but nothing I’ve tried so far has worked quite right.

For example, there’s a helpful 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 exactly what I’m looking for, except that if you try to use backspace or arrow keys it doesn’t work right. (I guess this is because cat is intercepting the keystrokes, which would normally be handled by the readline library in bash?) Does anyone have other suggestions?

Ultimately I’d like to have a way to launch a MATLAB process so that I can send commands to it from TextMate but also interact with it in the terminal. I use MATLAB for work, but am no great fan of its GUI or editor.

Edit December 19, 2010

Thanks for all the very helpful suggestions! I wanted to summarize the outcome of this for anyone who’s interested. I looked into rlwrap, but since my goal was to get this working inside a TextMate bundle that anyone could use, I was hesitant to rely on a non-standard utility (which I should have mentioned in the first place). I also checked on expect and unbuffer briefly, but, well, they seem pretty complicated and I just didn’t have the fortitude to dive in to that.

screen worked pretty well for this – as suggested below, I could open Terminal, start screen, start matlab -nodesktop, and then it was possible to have TextMate, for example, send the selected text to Matlab using screen -X ... inside a TextMate command. The shortcomings of this approach that I noticed were:

  1. Sending a block of text with more that 1,024 characters resulted in an error from `screen`; I figure there’s some buffer somewhere that can’t hold more than that, but didn’t spend any time trying to track it down.
  2. Screen has its own scrollback buffer, making Terminal’s scrollbar pretty useless. Maybe there’s an option to change how this works?
  3. Control-A is `screen`’s command keystroke; you can’t use it for moving to the beginning of the line unless you rebind the command key.

While I was playing around with screen, it occurred to me that although the question I asked is about connecting pipes and STDIN and so on, I actually only care about this for a very specific case: getting text from TextMate to Terminal. And that prompted me to try doing this with AppleScript, and surprisingly that turned out to be simpler and more robust than any of the other things I’d tried. Create a TextMate command that takes the selected text or current line as input, and contains

#!/usr/bin/env osascript

set input_command to do shell script "cat"

tell application "Terminal"
    do script input_command in window 1
end tell

And that works great, as long as MATLAB is in the frontmost Terminal window. (It’s also possible to search for a Terminal tab that’s running MATLAB, I just excluded that for clarity.)

The moral of this story is that I should ask more specific questions. Thanks again for all the help; I’ve learned a lot from wrestling with this!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T08:59:32+00:00Added an answer on May 18, 2026 at 8:59 am

    Give this a try:

    mkfifo alt_in
    (tail -f alt_in & rlwrap cat) | bash
    

    You won’t get a prompt, but you can enter commands and use arrow keys, etc., including history retrieval. You can echo commands from another terminal into the named pipe and they’ll be executed at the receiving end, but they won’t be in its history.

    Some other things to investigate:

    • expect
    • screen -x and screen -X

    For the latter, in one terminal start screen. You’ll be able to interact with Bash there pretty much as you normally would. Now on another terminal, do

    screen -ls
    

    to determine the PID of the screen session you started. It will be the digits at the start of a line that looks like this:

    31544.pts-2.hostname     (01/01/2010 01:01:01 PM)        (Attached)
    

    Now you can do things like this:

    screen -S 31544 -X stuff $'echo Your ad here.\n'
    

    which will cause the echo command to be executed on the other terminal. The $'' causes the escape sequences within to be interpreted, in this case giving us a newline so we can “press” Enter.

    Let’s say we did this:

    screen -S 31544 -X stuff $'top\n'
    

    Now top is running. We could go to that terminal and press q to quit, but where’s the fun in that?

    screen -S 31544 -X stuff 'q'
    

    Notice this time we didn’t need a newline.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.