1

I trying to write simple code that execute os command with parameters

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

target = "i586"

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

But it always start as /usr/bin/hsh --target=target instead of target=i586. Also subprocess.call not working cause python too old.

Please help me.

2
  • '"target"' is a string containing eight characters "target" and not the content of the variable target. Commented Mar 19, 2012 at 10:31
  • Please add your version of Python to the question Commented Mar 19, 2012 at 10:31

1 Answer 1

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

or

build = os.system('/usr/bin/hsh --target="' + target + '"')
Sign up to request clarification or add additional context in comments.

3 Comments

Nice.Thanks.But if i want more than one parameter i must build = os.system('/usr/bin/hsh --target="%s" --mountpoints="%s"' % target, mountpoints) ?
yes, but put brackets around the args: str % (arg1, arg2, arg3)
for multiple arguments forming the command first is much simple to understand, cmd = '/usr/bin/hsh --target="%s, %s, %s"' %(target1, target2, target3) then build = os.system(cmd)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.