python - Initializing a command that's failing with popen -
i trying run "repoinitcmd" using popen below , running following error..can provide inputs on wrong?
import subprocess branch_name='ab_mr2' repoinitcmd = 'repo init -u git://git.company.com/platform/manifest.git -b ' + branch_name proc = subprocess.popen([repoinitcmd], stderr=subprocess.pipe) out, error = proc.communicate()
error:-
file "test.py", line 4, in <module> proc = subprocess.popen([repoinitcmd], stderr=subprocess.pipe) 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 oserror: [errno 2] no such file or directory
by default, popen expects command line passed list. in particular, actual command run (in case 'repo') should first item of list. rather writing commands strings , using split or shlex pass them popen lists, prefer manage command lines lists start, makes easier build command line in code. so, in case might have written this:
repoinitcmd = ['repo', 'init', '-u', 'git://git.company.com/platform/manifest.git'] repoinitcmd.extend(['-b', branch_name]) proc = subprocess.popen(repoinitcmd, stderr=subprocess.pipe)
note, if want or need pass command line single string (perhaps take advantage of shell features), can enable shell mode if don't mind additional overhead of running shell process:
proc = subprocess.popen(repoinitcmd, shell=true, stderr=subprocess.pipe)
Comments
Post a Comment