Solved

call ipconfig from Python, then return select results into list or dictionary

Posted on 2013-11-25
4
2,019 Views
Last Modified: 2013-11-26
I want to all a cmd.exe function such as ipconfig from the REPL and return results into a list to do something else with. Any ideas how to do this?
 Thanks folks!!
0
Comment
Question by:SaffronThePuppy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 35

Expert Comment

by:Dan Craciun
ID: 39676699
ipconfig > file.txt

Works in cmd and powershell.

Or, if you want to append, use >>

In powershell, $i = ipconfig will store the result of the command in $i

HTH,
Dan
0
 
LVL 35

Accepted Solution

by:
Dan Craciun earned 500 total points
ID: 39676726
In Python, you can do

output = subprocess.check_output(['cmd.exe', '/c ipconfig'])

http://docs.python.org/2/library/subprocess.html

output will be a text variable, split it by endlines and you'll have your list.

HTH,
Dan
0
 

Author Closing Comment

by:SaffronThePuppy
ID: 39678799
Thank you, this answers the question. The actual command is a symcli command with complex output. It was calling the subprocess that I needed. Appreciated!
0
 
LVL 35

Expert Comment

by:Dan Craciun
ID: 39678928
Glad I could help. Thank you.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Installing Python 2.7.3 version on Windows operating system For installing Python first we need to download Python's latest version from URL" www.python.org " You can also get information on Python scripting language from the above mentioned we…
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question