473,395 Members | 1,986 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 1528
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
17
by: Paul | last post by:
HI! I get an error with this code. <SCRIPT language="JavaScript"> If (ifp==""){ ifp="default.htm"} //--></SCRIPT> Basicly I want my iframe to have a default page if the user enters in...
5
by: plugimi | last post by:
hi i've got kind of a strange problem i'm struggeling with here. this page: http://www.pohflepp.de/eavesdripping4.html won't be recognized as html/xml by firefox. i've tried everything that...
4
by: Paul | last post by:
HI! I have a script that does not seem to work. can someone tell me what I am doing wrong here? <script language="JavaScript"> function firefoxautofix(){ parent.window.resizeBy(-1,-1)...
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
46
by: Keith K | last post by:
Having developed with VB since 1992, I am now VERY interested in C#. I've written several applications with C# and I do enjoy the language. What C# Needs: There are a few things that I do...
13
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
2
by: Aaron Ackerman | last post by:
I cannot a row to this bound DataGrid to SAVE MY LIFE! I have tried everything and I am at a loss. The using goes into add mode with the add button adds his data then updates with the update...
98
by: tjb | last post by:
I often see code like this: /// <summary> /// Removes a node. /// </summary> /// <param name="node">The node to remove.</param> public void RemoveNode(Node node) { <...> }
8
by: watkinsdev | last post by:
Hi, I have created a mesh class in visual studio 6.0 c++. I can create a device, render objects and can edit the objects by for instancnce selecting a cluster of vertices and processing the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.