3

I tried almost every keyword on Google and still didn't came up with an answer. So hopefully one of you knows.

What is the terminal command keep a application running after it fails or stopped executing.

I tried this loop command in terminal:

bash -c 'while [ 0 ]; do COMMAND_HERE;done'

But it executes the commando immediately and not after the previous command failed or ended. I want the command to only execute if the process ended.

I want to use the command for ffmpeg while broadcasting a live stream. Some times the connection fails or some other issues happen. When that happens ffmpeg stops executing (obviously), but i want it to retry the same command again and again after it.

How do you do that?

Ps. I already tried these keywords on Google (i don't know why i still havent found any close answer):

  • mac execute command on fail
  • mac execute command synchronously
  • mac bash re execture terminal
  • mac loop command
  • mac re-run application if stops
  • mac terminal keep process
  • bash while terminal
  • mac terminal loop command
  • ffmpeg infinite
Journeyman Geek
  • 127,463
  • 52
  • 260
  • 430
sparkle
  • 133
  • 1
  • 3

1 Answers1

4

Try this from the bash prompt:

n=1 ; while true ; do echo -n "Command launch #$n: " ; sleep 1 ; n=$(( n + 1 )) ; done

Note: You may actually need sleep 1 in there, to allow for some cleanup before you re-launch.

Hannu
  • 8,740
  • 3
  • 21
  • 39