从python执行Shell脚本与变量

前端之家收集整理的这篇文章主要介绍了从python执行Shell脚本与变量前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有这个代码
opts.info("Started domain %s (id=%d)" % (dom,domid))

我想从上面执行一个带有参数domid的shell脚本.
这样的东西

subprocess.call(['test.sh %d',domid])

它是如何工作的?

我试过了:

subprocess.call(['test.sh',domid])

但是我收到这个错误

File "/usr/lib/xen-4.1/bin/xm",line 8,in <module>
    main.main(sys.argv)
  File "/usr/lib/xen-4.1/bin/../lib/python/xen/xm/main.py",line 3983,in main
    _,rc = _run_cmd(cmd,cmd_name,args)
  File "/usr/lib/xen-4.1/bin/../lib/python/xen/xm/main.py",line 4007,in _run_cmd
    return True,cmd(args)
  File "<string>",line 1,in <lambda>
  File "/usr/lib/xen-4.1/bin/../lib/python/xen/xm/main.py",line 1519,in xm_importcommand
    cmd.main([command] + args)
  File "/usr/lib/xen-4.1/bin/../lib/python/xen/xm/create.py",line 1562,in main
    dom = make_domain(opts,config)
  File "/usr/lib/xen-4.1/bin/../lib/python/xen/xm/create.py",line 1458,in make_domain
    subprocess.call(['test.sh',domid])
  File "/usr/lib/python2.7/subprocess.py",line 493,in call
    return Popen(*popenargs,**kwargs).wait()
  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

解决方法

喜欢这个 ?
subprocess.call(['test.sh',str(domid)])

文件可在python website

原文链接:https://www.f2er.com/python/186735.html

猜你在找的Python相关文章