「Python」os.system(command)

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 os
os.system('nvidia-detector')
执行之后得到返回“none”。内容换成以下两句话。

import os
os.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文件中可以调用。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值