python 执行Linux命令
python execute Linux commands:
1. os.system(command)
eg:
a = os.system("ls") print(a) # a 是命令的返回值,不是命令的输入值。 # a为0说明执行成功,不是0命令执行失败。
2. os.popen(command)
eg:
output = os.popen("ls -l") print(output.read()) output.close() # output是命令的返回对象,output.read()获取输出内容
3. subprocess