Reputation: 723
I am getting the following error when running the script below,can anyhelp to identify what the problem is and how to overcome it
import subprocess
import sys
import os
def main ():
to = ''
ssh_command = ["ssh", "-p", "29418", "review-android.quicinc.com", "gerrit",
"query", "--format=JSON", "--current-patch-set",
"--commit-message", "--files", ]
with open('gerrit_output.txt', 'a') as fp:
with open('caf_gerrits.txt','r') as f :
for gerrit in f :
print gerrit
result = subprocess.check_output(ssh_command + [gerrit, ])
print result
fp.write(result)
if __name__ == '__main__':
main()
ERROR:-
545804
Traceback (most recent call last):
File "test.py", line 20, in <module>
File "test.py", line 15, in main
File "/usr/lib/python2.7/subprocess.py", line 537, in check_output
process = Popen(stdout=PIPE, *popenargs, **kwargs)
File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1249, in _execute_child
raise child_exception
TypeError: execv() arg 2 must contain only strings
Upvotes: 20
Views: 33608
Reputation: 105
check all the values that you pass to the subprocess command. One of them isn't a string.
I had the same error
TypeError: execv() arg 2 must contain only strings
for
p1 = Popen(['aws', 'route53', 'change-resource-record-sets', '--hosted-zone-id', zone, '--change-batch', r53json], stdout=PIPE)
But as you can see it wasn't the 3rd parameter. The only variable was zone and I found that it was a list. Passing the parameter ass zone.id fixed the issue.
TypeError: execv() arg 2 must contain only strings
has all the clue you need.
Upvotes: 0
Reputation: 122
First you need to add the quotes around 29418
as mgilson mentioned. Second let's break down what you're trying to run:
ssh_command = ["ssh", "-p", 29418, "review-android.company.com", "gerrit",
"query", "--format", "JSON", "--current-patch-set",
"--commit-message", "--files", ]
That equals
ssh -p 29418 review-android.company.com gerrit query --format JSON --current-patch-set --commit-message --files
(then I'm assuming you have filenames in your caf_gerrits.txt file which get appended at the end)
One thing that pops out at me is that you may want to say --format=JSON
in which case your elements in the ssh_command
array should be combined as [..., "--format=JSON", ...]
. The other thing you may want to do is print result
after your result=
line to help with the debugging.
Upvotes: 3
Reputation: 309929
The third element in ssh_command
is an integer. It needs to be a string.
e.g:
ssh_command = ["ssh", "-p", 29418, ...
# ^ problem
And the solution is simple, just add some quotes:
ssh_command = ["ssh", "-p", "29418", ...
# ^Now it's a string.
Upvotes: 31