470,604 Members | 2,020 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,604 developers. It's quick & easy.

What am I doing wrong here

Hi,

I wanted to pass a popup mesage using windows messagin service to five
PCs.
If I just use following then PC1 gets the popup service message:

import os
os.system('net send PC1 "Message"')
But if I try to create a for loop like this it doesn't work.... how can
I pass computerName var as an argument?
What am I doing wrong here? Thank you in advance....

import os

Computerlist = ['PC1', 'PC2', 'PC3', 'PC4', 'PC5']
for ComputerName in Computerlist:
print ComputerName
os.system('net send ComputerName "Message"')

Apr 24 '06 #1
6 1459
ok here is the deal... I figured out how to pass the variable but now
messages are not popping up on the windows screen if I use this method:

import os

Computerlist = ['PC1', 'PC2', 'PC3', 'PC4', 'PC5']
for ComputerName in Computerlist:
print ComputerName
s = "net send %s" % ComputerName
os.system('s "Message"')

Apr 24 '06 #2
Hitesh Joshi a écrit :
(snip)
But if I try to create a for loop like this it doesn't work.... how can
I pass computerName var as an argument?
What am I doing wrong here? Thank you in advance....

import os

Computerlist = ['PC1', 'PC2', 'PC3', 'PC4', 'PC5']
for ComputerName in Computerlist:
print ComputerName
os.system('net send ComputerName "Message"')

What you pass to os.system is the litteral string 'net send ComputerName
"Message"'. This string is passed 'as is' - the fact that it contains
'ComputerName' won't invoke any magic...

Try this instead:
Computerlist = ['PC1', 'PC2', 'PC3', 'PC4', 'PC5']
for ComputerName in Computerlist:
os.system('net send %s "Message"' % ComputerName)

<ot>
In Python, CapitalizedNames are usually used for class names. You'd
better use all_lowers_with_underscores, or at least mixedCase.
</ot>
Apr 24 '06 #3
Hitesh Joshi wrote:
ok here is the deal... I figured out how to pass the variable but now
messages are not popping up on the windows screen if I use this method:

import os

Computerlist = ['PC1', 'PC2', 'PC3', 'PC4', 'PC5']
for ComputerName in Computerlist:
print ComputerName
s = "net send %s" % ComputerName
os.system('s "Message"')


s = 'net send %s "Message"' % ComputerName
os.system(s)

--
Robert Kern
ro*********@gmail.com

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

Apr 24 '06 #4
Thank you Robert, It worked!!!

Thank you so much....

Apr 24 '06 #5
Hitesh Joshi wrote:
Hi,

I wanted to pass a popup mesage using windows messagin service to five
PCs.
If I just use following then PC1 gets the popup service message:

import os
os.system('net send PC1 "Message"')
But if I try to create a for loop like this it doesn't work.... how can
I pass computerName var as an argument?
What am I doing wrong here? Thank you in advance....

import os

Computerlist = ['PC1', 'PC2', 'PC3', 'PC4', 'PC5']
for ComputerName in Computerlist:
print ComputerName
os.system('net send ComputerName "Message"')

Well... Just look at the name of the computer you are sending the
message to. Its looking for a computer named 'ComputerName', not
'PC1' ...

You want to create a command that has the computer's name in it, like
this: 'net send PC1', not like this 'net send ComputerName'. You have
several ways to from such a string. You have the same problem with the
message. Your message will be the string 'Message' not the contents of
a variable names Message. Try:

os.system('net send %s "%s"' % (ComputerName, Message))

(where the % operator replaces %s's on the left with values taken from the variables on the right)

or

os.system('net send ' + ComputerName + ' "' + Message + '"')

where the +'s build the command string up from pieces.

You might try invoking Python interactively and try typing some of these
expressions by hand to see that happens:

python
ComputerName = 'Fred'
Message = 'HI'
print 'net send ComputerName "Message"' net send ComputerName "Message" print 'net send %s "%s"' % (ComputerName, Message) net send Fred "HI"


Gary Herron

Apr 24 '06 #6
Thank you all for the quick replies. It worked! Truely appriciated. I
am python novice and still learning.... I hope to contribute to this
group someday :)

Hitesh

Apr 24 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by plugimi | last post: by
4 posts views Thread by Paul | last post: by
121 posts views Thread by typingcat | last post: by
46 posts views Thread by Keith K | last post: by
13 posts views Thread by Jason Huang | last post: by
8 posts views Thread by watkinsdev | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.