本文共 1165 字,大约阅读时间需要 3 分钟。
其实,简单理解的话:command > /dev/null 2>&1 和 command &> /dev/null 是一样的。就是把命令的标准输出和标准错误全都扔了!
[root@master ~]# ll no_exist.txtls: cannot access no_exist.txt: No such file or directory[root@master ~]# ll no_exist.txt > /dev/nullls: cannot access no_exist.txt: No such file or directory[root@master ~]# ll no_exist.txt > /dev/null 2>&1
[root@master ~]# ll no_exist.txtls: cannot access no_exist.txt: No such file or directory[root@master ~]# ll no_exist.txt > /dev/nullls: cannot access no_exist.txt: No such file or directory[root@master ~]# ll no_exist.txt &> /dev/null
当然,如果你想把标准输出和标准错误保存下来的话,/dev/null 也可以替换成具体的输出文件。
先贴个官网的链接:
你可以把下面的 ”=“ 理解为重定向。
import subprocesssubprocess.run(['command', 'param1', 'param2', 'param...'], stderr=subprocess.STDOUT, stdout=subprocess.DEVNULL)
这样的话,你就不用再写 os.system() (好多项目会觉得这个命令比较危险,写上的话基本上会被毙掉的!)了:
import osos.system('command param1 param2 param... &> /dev/null')# import subprocess# subprocess.getstatusoutput('command param1 param2 param... &> /dev/null')
export LANG="en_US.UTF-8"yum install python3yum install gccyum install python3-devel
转载地址:http://wsjqi.baihongyu.com/