【问题标题】:Is there a way to run several consecutive lines in the system command window using python [duplicate]有没有办法使用python在系统命令窗口中运行几行连续的行[重复]
【发布时间】:2019-11-07 14:06:08
【问题描述】:

我在命令窗口中按顺序使用了以下命令行。 cd path 1 && file.bat && cd path 2 && printfNav path3 > Testing.txt

是否可以通过python完成?

【问题讨论】:

    标签: python


    【解决方案1】:

    您正在寻找os.system() 方法。您需要将import os 输入到您的python 程序中,然后使用此方法您可以向终端发送命令。该方法接受一个字符串,就像您在终端中键入它一样。例如os.system('pwd') 会导致终端打印出您当前的工作目录,等等其他命令。

    【讨论】:

    • os.system 已弃用。不建议这样做。
    • subprocess.call() 将是更现代的方法,对此感到抱歉。更多文档可以在here找到。
    • 我能够获取 Windows 批处理文件中的所有命令并运行该命令。谢谢你的回答。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-13
    • 2014-03-22
    • 2013-10-06
    • 1970-01-01
    • 2013-03-04
    • 1970-01-01
    • 2020-10-10
    相关资源
    最近更新 更多