Discuss Cmd and Python in the Python Programming forum on Dev Shed. Cmd and Python Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
Posts: 16
Time spent in forums: 5 h 51 m 50 sec
Reputation Power: 0
Cmd and Python
I'm getting into python, and I had a nice idea for a program to use at my school. As most of you probably did at High school, you can shut down any pc on the network with cmd. I would want to make a graphical interface for this. It would work the following:
-Use net view to see which pc's are active, then try to find which is the user who's logged in.
-Mark with python on a school map which pc's are active and who's connected with information about them (name, class, etc.)
-Have an option to send messages with the net send command.
-Execute the shutdown command, with the possibility of including a comment and designate a timer.
-Display Net statistics
Now my question is the following, can I execute cmd commands through python and also read/use the data received in python?
Posts: 24
Time spent in forums: 13 h 14 m 44 sec
Reputation Power: 0
You can get into serious trouble with your school and the law for doing this. But you can run system commands by using the os module. I highly suggest that you use this information for something more constructive.
Posts: 16
Time spent in forums: 5 h 51 m 50 sec
Reputation Power: 0
Quote:
Originally Posted by knutrainer
You can get into serious trouble with your school and the law for doing this. But you can run system commands by using the os module. I highly suggest that you use this information for something more constructive.
Don't worry, my school isn't like that.
Thanks, I found the list which consist of the functions in the os module, could you give me a hint where to start? (I'm thinking about the os.system(command) function, but can't get my head around it)
Posts: 16
Time spent in forums: 5 h 51 m 50 sec
Reputation Power: 0
Quote:
Originally Posted by knutrainer
try putting quotes are around the command like this.
Code:
os.system("ping google.com")
Hmm, I didn't think about that
It works perfectly now, I've only got one last quetion left.
When I use the net view command a list of computers connected to a network is printed. How do I directly create a list with these names?
Posts: 16
Time spent in forums: 5 h 51 m 50 sec
Reputation Power: 0
Quote:
Originally Posted by b49P23TIvg
Your particular application may be better suited to a shell scripting language than to python.
Python's a poor language choice if your program looks like
import os
os.system('this')
os.system('that')
os.system('etceteras')
Probally there is a better way but we use python alot at school, and I know my way around it. That's why I wanted to use it for this project. The example you showed me only consisted about excecuting system commands, I would like to know how to interpret the information given by it. Example after net view a list like this prints itself: