1

Say you run an executable file in this way:

$ echo <params> | <process>

If process is not run as a pipe, then you type $ process & and it will stay running. What is needed in the command line above to launch process persistently?

Update:

More precisely, w3mimgdisplay can be run as a persistent process, that's how w3m keeps the images displayed on a terminal after scrolling. How can this program be run in such a way from the command line?

echo -e '0;1;0;0;0;0;0;0;0;0;file.png\n4;\n3;' | /usr/lib/w3m/w3mimgdisplay
  • By persistently do you mean to run it without any hangups? – Inian Jun 5 '17 at 5:30
  • @Inian I mean that the process keeps running. I'm not sure what's the difference between nohup and &. – nightcod3r Jun 5 '17 at 5:36
  • nohup is used in conjunction with & to run a process immune to any hangups – Inian Jun 5 '17 at 5:38
  • @Inian But I don't see how to make it work in a pipe. Please, check the example added to the question. – nightcod3r Jun 5 '17 at 5:40
2

It seems you need named pipes:

https://askubuntu.com/questions/449132/why-use-a-named-pipe-instead-of-a-file

Basically, you create a named pipe, run the process which gets input from the named pipe, and then pass whatever you want TO the named pipe for it to be processed by the process.

For example:

mkfifo /tmp/namedpipe
tail -f /tmp/namedpipe &
echo "BOO"> /tmp/namedpipe
echo "this" > /tmp/namedpipe

... This will echo (by tail) to stdout everything that is sent to the /tmp/namedpipe.

I use tail instead of cat, because cat will exit the process when it receives EOF.

UPD. Clarification.

To pass this to your process you need to do something like this:

tail -f /tmp/namedpipe | yourprocess &

UP2. So in your case the sequence would be like this:

mkfifo /tmp/namedpipe 

--- this will be the entry point through which you can send data to your process.

tail -f /tmp/namedpipe |  /usr/lib/w3m/w3mimgdisplay &

-- this will then create the persistent process that you want, and will in future feed to it antyhing you send through the pipe.

echo -e '0;1;0;0;0;0;0;0;0;0;file.png\n4;\n3;' > /tmp/namedpipe

Should show you the image on the screen.

From now on, any further things that you will send to /tmp/namedpipe will be like new lines echoed to the command and should likewise appear on the screen.

  • If I got it right, for the example in the question, the sequence would be: mkfifo /tmp/namedpipe tail -f /tmp/namedpipe & echo -e '0;1;0;100;0;0;0;0;0;0;roby_body.png\n4;\n3;' > /tmp/namedpipe tail -f /tmp/namedpipe | /usr/lib/w3m/w3mimgdisplay & . By executing a batch with all this, it does not show the image on the terminal. – nightcod3r Jun 5 '17 at 14:40
  • Not really, no. Let me convert the answer for your case exactly. – Gnudiff Jun 5 '17 at 14:44
  • Note that all of this only makes sense if you are going to feed more echo commands to the w3mimgdisplay through the pipe. For single echo your original command is quite enough. – Gnudiff Jun 5 '17 at 14:51
  • Let me know, if this worked. – Gnudiff Jun 5 '17 at 14:51
  • 1
    The process indeed stays, this is a solution. Thanks! – nightcod3r Jun 5 '17 at 14:54

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.