?
Solved

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

Posted on 2013-11-25
4
Medium Priority
?
2,220 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
  • 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 2000 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

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

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

Strings in Python are the set of characters that, once defined, cannot be changed by any other method like replace. Even if we use the replace method it still does not modify the original string that we use, but just copies the string and then modif…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses
Course of the Month14 days, 10 hours left to enroll

840 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