如何让 python 打开一个 cmd 并设置 : cd 然后命令我需要使用

How can I make python open a cmd and set : cd and then command that I need to use

我想制作脚本来打开并使用 scrcpy 命令预先设置 cmd。 我试过像 os,subprocess,pyautogui 这样的模块 当我尝试使用 os 打开 cmd 并使用 pyautogui 在其中键入时,它没有用 我应该用什么来输入命令。 我需要写的只是 'cd "directory"' 和 scrcpy 但我找不到用 python

来做的方法

您可以使用以下代码:

import os
os.system('cmd /c "Your Command Prompt Command"')

这是执行此操作的代码

import os as os
os.startfile("cmd.exe")

并且运行命令使用

os.system("Your Command")

这将显示您传递到 cmd 终端的命令。