0

I wanted to pass two parameter in the subprocess call... like this...

./buildbot sendchange --branch=poky --property=buildname:nice --property=machine:qemux86

So I wrote the below program...

# property_name = {'key': 'value'}
y = ['--property={}:{}'.format(key, value) for key, value in property_name.items()]
cmd = [
    './buildbot', 'sendchange',
    '--branch={}'.format(
        branch),
    y
]

And above command throws error by subprocess!

Traceback (most recent call last):
  File "/home/iaskin/Workspace/latest/local/lib/python2.7/site-packages/django/core/handlers/exception.py", line 39, in inner
    response = get_response(request)
  File "/home/iaskin/Workspace/latest/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 249, in _legacy_get_response
    response = self._get_response(request)
  File "/home/iaskin/Workspace/latest/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 187, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/home/iaskin/Workspace/latest/local/lib/python2.7/site-packages/channels/handler.py", line 227, in process_exception_by_middleware
    return super(AsgiHandler, self).process_exception_by_middleware(exception, request)
  File "/home/iaskin/Workspace/latest/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 185, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/iaskin/Workspace/latest/local/lib/python2.7/site-packages/django/contrib/auth/decorators.py", line 23, in _wrapped_view
    return view_func(request, *args, **kwargs)
  File "/home/iaskin/Workspace/buildsys/build_app/views.py", line 93, in home
    property_name=property_name
  File "/home/iaskin/Workspace/buildsys/build_app/helper/build_agent.py", line 50, in submit_buildbot
    output = subprocess.Popen(cmd, cwd=bb_master_dir)
  File "/usr/lib/python2.7/subprocess.py", line 711, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1343, in _execute_child
    raise child_exception
TypeError: execv() arg 2 must contain only strings

So I changed the above code to this

y = ['--property={}:{}'.format(key, value) for key, value in property_name.items()]
cmd = [
    './buildbot', 'sendchange', '--master=bsp-buildvm:9999',
    '--branch={}'.format(
        branch),
    "{}".format(' '.join(y))
]

And this is I don't want ...

./buildbot sendchange --branch=poky "--property=buildname:nice --property=machine:qemux86"

So am I doing anything wrong ? Or Is subprocess really doesn't allow this then what are the other alternatives ?

1 Answers1

0

In parent process save argument as environment variables. Child process can access it.

forvaidya
  • 3,041
  • 3
  • 26
  • 33
  • Hi... can you explain more! What do I need to change in the code ? –  Aug 10 '16 at 09:19
  • os.environ['KEY'] = "my-personal-key" --- this type of construct will set an environment variable. Child process can inherit those env vars. – forvaidya Aug 10 '16 at 09:20
  • okay after setting the env then how do I change my `cmd` code ? –  Aug 10 '16 at 09:29
  • Please can you explain clearly in your answer! I'm not getting what you are trying to say.. –  Aug 10 '16 at 09:35