简体   繁体   English

运行带有和不带输出的python脚本

[英]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. 我有问题,我需要运行一个没有输出到屏幕的备份脚本所有的问题是我需要这样做只有它从Linux的crontab运行。

So if a user open the script it will load the UI menu 因此,如果用户打开脚本,它将加载UI菜单

But from the crontab i want to add an argument so it will run without any output, something like: 但是从crontab我想添加一个参数,所以它将运行没有任何输出,如:

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

s for silent :) s为沉默:)

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 . 您可以将所有输出(stdout和stderr)转储到/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 ). 2>&1基本上意味着,将stderr( 2 )转储到转储stdout( &1 )的位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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