Writing Command Line Applications – Tips & Tricks – Run the command in background

Sometimes commands takes too much time to finish. And during its running process, your terminal should always be online! If you close your terminal or you lose your internet connection, process will interrupt.

To avoid this problem, there are many different approaches. If your command takes too much time and you afraid it gets terminated because of you, you can use nohup to run command in background.

nohup php artisan command:name &

It will run the command in background and you can close your connection. When you run the command, you’ll see such message:

nohup: ignoring input and appending output to 'nohup.out'

This means, all output will be stored under nohup.out file. You can tail it while your command is running. tail -f nohup.out

I prefer to save logs in specific folder and file.

nohup php artisan command:name &> /path/to/your/specific/file.log &

Leave a Reply

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir

%d blogcu bunu beğendi: