如何运行cmd命令python

代码示例

3
0

python运行系统命令

import os
cmd = "git --version"
returned_value = os.system(cmd)  # returns the exit code in unix
1
0

rum系统命令python

import os
command = "ls"  #The command needs to be a string
os.system(command) #The command can also be passed as a string, instead of a variable
1
0

如何运行cmd命令python

import subprocess
subprocess.run(["ls", "-l"])

其他语言

此页面有其他语言版本

Русский
..................................................................................................................
English
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................