Execute command without terminal output

40,580

Solution 1

If you don't need the output at all then redirect it to /dev/null

yourcommand > /dev/null 2>&1

otherwise you can redirect into a file:

yourcommand > /somwhere/file 2>&1

And as you run the command from another application and you want use your news reader immediately you may want to run the command in the background. I am not sure how it works in this newsboat, but in a shell you can send programs into the backround with &

yourcommand > /somwhere/file 2>&1 &

Solution 2

To run command silently in background, which will "survive" even if terminal will be closed afterwards, use screen in detached mode:

screen -dm your_command(-s)

to reattach screen with the command running execute

screen -r

To detach reattached screen press CTRL+A+D.

Without screen you should execute your command with nohup, thus the process will run if the terminal is closed afterwards, like the screen utility:

nohup your_command(-s) &>/dev/null  &
Share:
40,580

Related videos on Youtube

Admin
Author by

Admin

Updated on September 18, 2022

Comments

  • Admin
    Admin over 1 year

    Let me give a bit of background to my question. I am using a terminal RSS reader newsboat which allows for the usage of macros to operate on links. For example, I have a macro running cd ~/videos && youtube-dl %u, which will download a youtube video to ~/videos. However, the output of youtube-dl will be printed in my terminal until the download is complete and for this time I cannot continue using newsboat.

    I am wondering how I could phrase the command so that it is executed “somewhere else” so that I can immediately continue using the terminal from which it is run.

    • Admin
      Admin almost 6 years
      Why the downvote? I know that applications like youtube-dl are off-topic, but I think my question is not.
    • Admin
      Admin almost 6 years
      Please specify: Are you asking about discarding output, or are you asking about job control (e. g. running processes in the background)?
    • Admin
      Admin almost 5 years
      @JohnDorian Here is a +1 to compensate that :)
  • Admin
    Admin almost 6 years
    I think I need both discarding output and background here. (Since I am quite a newbie, I couldn't specify the abstract concepts I was looking for, that's why I gave my concrete context.) Thank you for pointing me to the concept of job control, I will certainly read more on this topic!
  • an offer can't refuse
    an offer can't refuse over 4 years
    what does 2>&1 mean?
  • redseven
    redseven over 4 years
    2>&1 redirects the stderr (2) to the stdout (1). As the stdout is redirected to a file, it writes the stderr to the same file.