By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,907 Members | 1,932 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,907 IT Pros & Developers. It's quick & easy.

How to launch cmd window, and excute command within the cmd window with Python script

P: 2
I want to write a Python script to do following:
1. launch cmd window
2. execute dos command within cmd window.

I tried following:

command = r'start "test" cmd'

=> it is able to launch a cmd window with "test" title.

What is the syntax for not only launch the cmd window, but also able to execute a command, like run a python script.

I tried to do
command = r 'start "test" cmd ("dir")'
- expect it launch the cmd window, and excute "dir" command, doesn't work.
Sep 20 '10 #1
Share this Question
Share on Google+
2 Replies

Expert 100+
P: 624
Try Pexpect, a Python module written to run programs and watch their output from Python.
Sep 20 '10 #2

P: 2
Before I spend time studying the Pexpect as you mentioned, wondering if this works well under Window's environment. If not, what will be the solution?
Oct 5 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.