Run windows command line command using python

I was just playing with my python interpreter in my windows 7 system today and thinking what to do silly,fun.

Then just searched for the library in python which can be used to list windows directory/file.

The OS module is used in this case and it was simple.I put the windows command that I want to execute and passed it inside popen() .


windows = "dir"
command = os.popen(windows).read()
print command

Its simple 🙂

If any one have better solution than this please drop a line,that I can know that.

To know details about python’s OS module,click here.

Advertisements