0

以下の ssh コマンドを python コードに変換しようとしていますが、python に変換できましたが、python コードからは出力が得られないため、特にブール値の "AND" ロジックを適切に変換できなかったと思います。ここで何が問題なのですか?

ssh -p 29418 company.com gerrit query --current-patch-set --commit-message --files 'status:open project:platform/code branch:master label:Developer-Verified=1 AND label:Code-Review>=1'

Python コード:-

with open(timedir + "/ids.txt", "wb") as file:
    check_call("ssh -p 29418 company.com "
        "gerrit query --commit-message --files --current-patch-set "
        "status:open project:platform/code branch:master label:Developer-Verified=1 AND label:Code-Review>=1 |"
        "grep refs |"
        "cut -f4 -d'/'",
            shell=True,   # need shell due to the pipes
            stdout=file)  # redirect to a file
4

2 に答える 2

1

>=1ファイルへのリダイレクトとして解釈される可能性がある=1ため、ids.txt ファイルに出力がありません。

check_call() で使用する文字列は、gerrit の引数を引用していません。引数を引用する最初のコマンドと比較してください。

pipes.quote()シェルの単一のコマンドライン引数として文字列をエスケープするために使用できます。

于 2013-01-20T07:43:48.760 に答える
1

Paramikoを使用して ssh 経由で接続する

import paramiko
ssh = paramiko.SSHClient()
ssh.connect('127.0.0.1', username='xxx', 
    password='xxx')

その後、subprocesspython モジュールを使用してシステム コールを実行できます。

Python で外部コマンドを呼び出す

于 2013-01-20T07:45:01.033 に答える