python中的系统函数是什么

2024-05-12 20:14:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我想玩python中的系统命令。例如,我们在perl:system(“ls-la”)中有这个函数,它的run ls-la在python中是什么系统函数? 提前谢谢。


Tags: 函数run系统systemlslaperl系统命令
3条回答

它是^{}

import os
os.system('ls -la')

但这不会给你任何输出。所以^{}可能更符合您的需求:

>>> import subprocess
>>> subprocess.check_output(["ls", "-l", "/dev/null"])
'crw-rw-rw- 1 root root 1, 3 Oct 18  2007 /dev/null\n'
import os
os.system("")

来自here

os模块中有^{}

但是,如果您想用子流程做更高级的事情,^{}模块提供了一个更高级别的接口,通常更可取。

相关问题 更多 >