每当使用python执行shell命令时,操作系统和子进程返回代码1

每当使用python执行shell命令时,操作系统和子进程返回代码1,python,powershell,operating-system,subprocess,Python,Powershell,Operating System,Subprocess,一, CompletedProcess(args=['cd'],returncode=1,stdout=b'',stderr=b'') 每当我运行这些命令时,我的返回代码都是1。我尝试安装并重新安装powershell。我有python 3.9.1这与powershell有什么关系?看起来您正在调用cmd.exe。。。 import os os.system('ls') import subprocess subprocess.run(['cd'], shell=True, stdout

一,

CompletedProcess(args=['cd'],returncode=1,stdout=b'',stderr=b'')


每当我运行这些命令时,我的返回代码都是1。我尝试安装并重新安装powershell。我有python 3.9.1

这与powershell有什么关系?看起来您正在调用
cmd.exe
。。。
import os
os.system('ls')
  
import subprocess
subprocess.run(['cd'], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)