如何通过python子进程传递两个相同的参数?

时间:2016-08-10 08:49:38

标签: python django subprocess buildbot

我想在子进程调用中传递两个参数...像这样......

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

所以我写了下面的程序......

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

以上命令会抛出子进程错误!

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

所以我将上面的代码更改为

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))
]

这是我不想......

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

我做错了什么?或subprocess真的不允许这样做,那么其他选择是什么?

1 个答案:

答案 0 :(得分:0)

在父进程中将参数保存为环境变量。子进程可以访问它。