2012-03-19 35 views
0

我尝试写简单的代码,执行与参数使用os.system(旧蟒蛇)和参数与参数

#!/usr/bin/env python 
# -*- coding: utf-8 -*- 
import os 

target = "i586" 

build = os.system('/usr/bin/hsh --target="target"') 

但它总是开始为在/ usr/bin中/ HSH --target =目标,而不是操作系统命令目标= i586。 也subprocess.call不工作导致python太旧。

请帮帮我。

+0

' ' “目标”''是包含八个字符' “目标”'而不是变量'target'的内容的字符串。 – eumiro 2012-03-19 10:31:06

+0

请将您的Python版本添加到问题 – 2012-03-19 10:31:38

回答

3
build = os.system('/usr/bin/hsh --target="%s"' % target) 

build = os.system('/usr/bin/hsh --target="' + target + '"') 
+0

Nice.Thanks.But如果我想要多个参数,我必须 build = os.system('/ usr/bin/hsh --target =“%s”--mountpoints =“%s”'%target,mountpoints)? – Alexander 2012-03-19 10:40:39

+0

是的,但在args周围放置括号:str%(arg1,arg2,arg3) – j13r 2012-03-19 10:42:15

+0

首先形成命令的多个参数很容易理解,'cmd ='/ usr/bin/hsh --target ='%s ,%s,%s“'%(target1,target2,target3)'然后'build = os.system(cmd)' – avasal 2012-03-19 10:53:45