1

I am trying to understand how to access stdin an stdout for a process.

I have a remote machine accessible only by SSH and I want to run a terminal based program in the background. That is, I fire up the the program through ssh-terminal in detached mode so that the ssh-connection can be closed.

And this program has its own terminal-based interface and it listens user input from stdin and outputs to stdout.

My question is that how can I pipe the stdin/stdout so that it can be accessed by some other terminal in the remote machine? That is I open a new ssh-terminal and the simply access the detached program.

Or how can I pipe in/out so that it can be tunneled through ssh to my local machine and use it there in the same manner?

I cannot use screen in the remote machine to achieve the effect because it is too old, and I cannot upgrade it. Also there is no tmux installed.

However both of these programs are accessible in the local machine, so if any kind of tunneling is possible, then it might solve the problem.

6
  • Until the last sentence, I thought : Use screen. This is exactly what screen (or tmux) is made for. Why can't you use one of these? Please explain a little bit your setup and restrictions so that we can provide good answers. (stdout can be captured also with nohup, but not sure about stdin).
    – pLumo
    Feb 13 at 8:18
  • The container I am using has too old sceen and there does not seem to be tmux installed at all.
    – M.L.
    Feb 13 at 8:24
  • What version of screen is installed and how did you determine that it's too old?
    – Kusalananda
    Feb 13 at 8:37
  • Screen version is 4.01.00devel (GNU) 2-May-06 and it does not like unicode-characters.
    – M.L.
    Feb 13 at 8:43
  • How do you plan to provide input to a background process reading from stdin? A few suggestions here: serverfault.com/questions/188936/…. Feb 13 at 8:58
1

There might be a better way to do this but you could use mkfifo to create two FIFO files and run the command / script in such a way that it redirected the input and output of the program to the two FIFO files.

So once you ran the command and had your two files created (and closed your SSH connection), when you were ready to send input to the process you would just use SSH to echo whatever input you were trying to send into the FIFO file and it would then be redirected to the running process.

The output would then be send to the output FIFO where it would then be able to be read line by line by whatever program needed to access it when it was ready to access it.

Fair warning, I’m not at a computer right now so this may not be totally right - I often get mixed up whether a FIFO or a regular old temporary file is the right tool for the task at hand (you might just need a FIFO for the input & redirect the output to a temp file created via mktemp), but I suspect the final solution will at least somewhat resemble what I described above, i.e. some redirection wizardry.

Good luck! Hopefully someone else will be able to give you a more concrete answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.