Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 2nd, 2012, 05:18 AM
leeuw01 leeuw01 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 16 leeuw01 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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?

Reply With Quote
  #2  
Old December 2nd, 2012, 11:33 AM
knutrainer knutrainer is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Location: U.S A.Z.
Posts: 24 knutrainer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 14 m 44 sec
Reputation Power: 0
Send a message via AIM to 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.
Comments on this post
leeuw01 agrees: A thank you for your help

Reply With Quote
  #3  
Old December 2nd, 2012, 12:45 PM
leeuw01 leeuw01 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 16 leeuw01 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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)

Reply With Quote
  #4  
Old December 2nd, 2012, 02:12 PM
knutrainer knutrainer is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Location: U.S A.Z.
Posts: 24 knutrainer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 14 m 44 sec
Reputation Power: 0
Send a message via AIM to knutrainer
try putting quotes are around the command like this.
Code:
os.system("ping google.com")

Reply With Quote
  #5  
Old December 3rd, 2012, 11:34 AM
leeuw01 leeuw01 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 16 leeuw01 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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?

Reply With Quote
  #6  
Old December 3rd, 2012, 12:15 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,352 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 7 h 49 m 23 sec
Reputation Power: 383
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')
__________________
[code]Code tags[/code] are essential for python code!

Reply With Quote
  #7  
Old December 3rd, 2012, 01:42 PM
leeuw01 leeuw01 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 16 leeuw01 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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:

\\PC-INFO-01
\\PC-INFO-02
\\PC-INFO-03
\\PC-SVT-01
\\PC-SVT-02

How would I instead of printing it place it into a list. Ex: PClist["\\PC-INFO-01","\\PC-INFO-02", etc..]

Reply With Quote
  #8  
Old December 3rd, 2012, 01:49 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,352 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 7 h 49 m 23 sec
Reputation Power: 383
A=subprocess.check_output('theCommandYouWouldHaveUsedFor_os_dot_system',shell=True).split('\n')

warning, the list is a list of bytes objects (python 2) which you may have to mess with.

Reply With Quote
  #9  
Old December 3rd, 2012, 02:17 PM
leeuw01 leeuw01 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 16 leeuw01 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 51 m 50 sec
Reputation Power: 0
Quote:
Originally Posted by b49P23TIvg
A=subprocess.check_output('theCommandYouWouldHaveUsedFor_os_dot_system',shell=True).split('\n')

warning, the list is a list of bytes objects (python 2) which you may have to mess with.


I'll try to figure something out. Thanks for the help

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Cmd and Python

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap