Solved

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

Posted on 2013-11-25
4
1,939 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article will show, step by step, how to integrate R code into a R Sweave document
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
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)

726 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