博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Linux 中的 &> /dev/null
阅读量:4229 次
发布时间:2019-05-26

本文共 1165 字,大约阅读时间需要 3 分钟。

其实,简单理解的话:command > /dev/null 2>&1 和 command &> /dev/null 是一样的。就是把命令的标准输出和标准错误全都扔了!

command > /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 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

当然,如果你想把标准输出和标准错误保存下来的话,/dev/null 也可以替换成具体的输出文件。

在 python3 的 subprocess 里边对应的语法:

先贴个官网的链接:

你可以把下面的 ”=“ 理解为重定向。

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/

你可能感兴趣的文章
16.一级目录、历史命令,du,date,zip,快捷方式
查看>>
MySQL的基本管理
查看>>
MySQL 表结构与键值
查看>>
MySQL存储引擎,表记录管理
查看>>
Mysql多表查询语句,授权用户与密码更改
查看>>
MySQL 备份与恢复
查看>>
采用IC传感器的相对湿度测量
查看>>
皮带传动实验
查看>>
微软的人才观
查看>>
Blizzard的MPQ文件格式搜索算法
查看>>
你的变量究竟存储在什么地方?
查看>>
s3c2410 中断异常处理(转)
查看>>
对张孝祥C语言试题其中一题的探讨 (转载)
查看>>
一些好的网站
查看>>
WinCE中的虚拟地址和实际的物理地址是如何对应
查看>>
Microsoft Windows CE 的内存使用
查看>>
makefile入门
查看>>
中科院计算所Goddon CPU诞生历史!牛!
查看>>
ispPAC
查看>>
为人处世小技巧
查看>>