首页 > 文章列表 > python os.system执行cmd指令

python os.system执行cmd指令

Python os.system
345 2022-08-07

1、执行cmd指令,在cmd输出的内容会直接在控制台输出,返回结果为0表示执行成功。

2、在调用完shell脚本后,返回一个16位的二进制数,低位为杀死所调用脚本的信号号码,高位为脚本的退出状态码。

os.system()方法是简单粗暴的执行cmd指令,没有办法获取到cmd输出的内容。

实例

# coding:utf-8
 
import os
 
os.system("ls")

本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。