我正在执行os.system("unit run" + 目录路径+ " urun shell"),它打开了单元的外壳提示符,如何在外壳程序上运行命令?



我正在运行命令os.system("unit run" + directoryPath + " urun shell"),这将打开单元的shell提示符。我应该如何在shell提示符上运行命令,这是一个全新的Python提示符?

我尝试执行命令os.system("unit run" + directoryPath + " urun shell /c command"),但这没有工作,因为我期望命令应该在shell提示符上运行。

据我所知,您可以使用shell命令再次调用os.system()

使用子流程模块:

import subprocess
subprocess.run(["unit", "run", directoryPath, "urun" "shell"], shell=True, check=True)

注意,您可能需要在directoryPath值中包含转义引号:

directoryPath = '"some directory path"'

最新更新