The background script seems to work perfectly, but it's not quite true. my_script.pyģ012286 pts/ 1 S+ 0: 00 grep - color= auto my_script.pyĪfter finishing the process all script output will be saved to output.log. We can see our process using the next command: ps ax | grep my_script. If you run a few scripts with the same name they all will be stopped. It is also possible to kill the process by using pkill command. If you want to stop the script before its ending you can use the kill command: kill PID We save the script's output to the log file, so after running this command we will get output like this in the terminal: 3010186 Print(f "Start time: ")įor running the script use the next command: your/ path/my_script.py > output. For example, a simple script that will have been printing time during the next ten seconds. Now we need some logic that will show us that the script is running in the background. ![]() ![]() This allowed you don't indicate in the terminal that it is a python script. Then I recommend adding a shebang line to the top of this file. At first, we need to add execution permission for this file using the next command: chmod +x my_script.py ![]() But at first, we need to prepare our script for this.įor example, we have a python file my_script.py. If you want to run a python script in the background you can use an ampersand(&).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |