0
def OnClick(self,event):
    print "a:", a
    os.system('iperf -s -w a')

Here a is displayed correctly. But in the os.system command the value of a is taken as 0. Could you please help me on this?

1
  • Try creating this command separately to avoid such errors. Something like <command = 'iperf -s -w {}'.format(a) > or if 'a' is always string then you can also use %s. <command = 'iperf -s -w %s'%a > Commented Dec 24, 2013 at 6:24

2 Answers 2

2

You are not passing the value of a, but you are passing a as it is. So, you might want to do this

os.system('iperf -s -w {}'.format(a))

Now, the value of a will be substituted at {}. You can see the difference between both the versions by printing them

print 'iperf -s -w {}'.format(a)
print 'iperf -s -w a'
Sign up to request clarification or add additional context in comments.

9 Comments

thank u..got it..Could you please tell me any other ways to call an external command and the output of the command has to be displayed also..
@user3131595 You might want to look at subprocess.check_output
>>> subprocess.check_output(["echo", "Hello World!"]) Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'subprocess' is not defined >>>
Did you import subprocess?
@user3131595 Can you please add the updated code to the question?
|
0
os.system('iperf -s -w a')

takes literal a and not the value of the variable. I would use:

cmd = 'iperf -s -w %d' %a
os.system (cmd)

Refer input output formatting in python

Comments

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.