If I type this command at a command prompt
start cmd /k ipconfig > {file_name}
it doesn't redirect the output from ipconfig
. It opens a new console and in that console it runs ipconfig
, sending output to the screen. start
produces no output of its own, so the >
redirects non-existent output from start
to {filename}
and creates a zero-byte output file.
To do the redirection using start
you need to associate the >
with ipconfig
like this:
start cmd /k "ipconfig > {file_name}"
But if you're planning to invoke a shell from a Python program, it's usually not handy to open a console window and leave it there. If I type this simpler command at the command prompt
ipconfig > {file_name}
it works as you describe. Likewise,
os.system(r"ipconfig > C:\users\.blah.\{file_name}")
will work in Python, but you need to specify the path of the output file, because otherwise os.system()
will probably try to send the file to a default location that you're not permitted to write to (because it is a subfolder of Program Files
). Use an r
-string so that you don't have the hassle of doubling backslashes.
And consider using the subprocess
module in preference to os.system
.