「Python」os.system(command)

来源:互联网 发布:大数据用什么语言最好 编辑:程序博客网 时间:2024/06/04 19:34

Sina Weibo:小锋子Shawn
Tencent E-mail:403568338@qq.com
http://blog.csdn.net/dgyuanshaofeng/article/details/77951885

1、Python2的文档os.system(command)

2、下面是文档的翻译和理解:

Execute the command (a string) in a subshell. 

在subshell执行命令,该命令是一个字符串。比如:新建一个python文件,输入下面两句话,然后执行这个文件。

import osos.system('nvidia-detector')
执行之后得到返回“none”。内容换成以下两句话。

import osos.system('nvidia-smi')
执行之后得到返回一个表格,表格里面是关于GPU的信息。与直接在终端中输入nvidia-smi等价。

This is implemented by calling the Standard C function system(), and has the same limitations.

解释具体的调用。命令通过调用system()而执行。

Changes to sys.stdin etc. are not reflected in the environment of the executed command.

解释“limitations”?

On Unix, the return value is the exit status of the process encoded in the format specified for wait().

On Windows, the return value is that returned by the system shell after running command, given by the Windows environment variable COMSPEC: on command.comsystems (Windows 95, 98 and ME) this is always 0; on cmd.exe systems (Windows NT, 2000 and XP) this is the exit status of the command run; on systems using a non-native shell, consult your shell documentation.

The subprocess module provides more powerful facilities for spawning new processes and retrieving their results; using that module is preferable to using this function. See the Replacing Older Functions with the subprocess Module section in the subprocess documentation for some helpful recipes.

Availability: Unix, Windows.

后面的信息不想翻译了,总之,在Ubuntu的终端或者在Windows的CMD执行的命令,在Python文件中可以调用。

原创粉丝点击