0

I am trying to convert the below ssh command to python code,I was able to convert to python but the python code doesnt give any output,so i think i did not convert it properly especially the boolean "AND" logic..can anyone point what is wrong here?

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 code:-

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

2 Answers 2

1

Use Paramiko to connect via ssh

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

Then you can use the subprocess python module to execute system calls.

Calling an external command in Python

Sign up to request clarification or add additional context in comments.

Comments

1

>=1 might be interpreted as a redirect to =1 file that is why there is no output in the ids.txt file.

The string that you use in check_call() doesn't quote the gerrit's argument. Compare it with the first command that does quote the argument.

You could use pipes.quote() to escape a string as a single command-line argument for shell.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.