简体   繁体   中英

run python script with and without output

I have h problem, i need to run a backup script with no output to the screen at all the problem is i need to do it only if its running from the crontab in linux.

So if a user open the script it will load the UI menu

But from the crontab i want to add an argument so it will run without any output, something like:

07 00 * * *     /root/idan/python nw_backup.py -s

s for silent :)

From my search here i found how to run only one command with subprocess module

Thanks !

You can just dump all output (stdout and stderr) to /dev/null .

/root/idan/python nw_backup.py -s > /dev/null 2>&1

2>&1 basically means, dump stderr ( 2 ) same to where you dump stdout ( &1 ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM