user3131595
user3131595

Reputation: 15

External command from python

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?

Upvotes: 0

Views: 620

Answers (2)

Vamsi Krishna
Vamsi Krishna

Reputation: 485

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

Upvotes: 0

thefourtheye
thefourtheye

Reputation: 239453

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'

Upvotes: 2

Related Questions