Bash – When I run `./command.sh &`, the background task is suspended. How to keep it running

background-processbashjob-control

This is what I'm running:

alexandma@ALEXANDMA-1-MBP ./command.sh &
[2] 30374
alexandma@ALEXANDMA-1-MBP
[2]  + suspended (tty output)  ./command.sh

I don't want it to start suspended, I want it to keep running in the background. I'm going to be running a bunch of these in a loop, so I need something that will work that way.

How can I keep it running?

Best Answer

It stops because of the reason given: it tries to output to tty. You can try to redirect the output if ./command.sh supports that, or run the command in a tmux or screen window of it's own. E.g.

 tmux new-window -n "window name" ./command.sh

and then view the list of windows created with tmux list-windows and attach to tmux with tmux attach.

That way the program will still wait for input/output to happen, but you can easily provide input once you go to the appropriate window and the output will just be captured without any activity.