如何在python中运行git bash命令?

时间:2019-07-08 23:31:57

标签: python python-3.x git git-bash

我在git bash终端(不是Windows命令行或mac的终端)中运行以下命令。

ssh username@code.companyname.com -p 12356 gerrit query --format=JSON --current-patch-set --files change: 878545

当我在git bash中运行它时会生成一个JSON输出。我正在尝试使用以下命令在Python文件中执行相同的操作:

import subprocess
result = subprocess.run(
    [
        "ssh",
        "-c",
        "aes128-cbc", #adds necessary ciphers
        "username@code.companyname.com",
        "-p",
        "12356",
        "gerrit",
        "query",
        "--format=JSON",
        "--current-patch-set",
        "--files",
        "change: ",
        "878545",
    ], stdout=subprocess.PIPE,
       stderr=subprocess.STDOUT,
       shell=True

)
result_process = result.stdout.decode("utf-8")
print(result_process)

但这产生了错误:'ssh' is not recognized as internal or external command, operable program or batch file.

ssh在命令行中工作。

0 个答案:

没有答案