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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s