[python-win32] regarding invoking command prompt using python
timr at probo.com
Wed Jun 17 20:54:52 CEST 2009
a h wrote:
> thanks for the reply, what i have done to set up the environment
> variables is open the command prompt and then has given the whole path
> of c:\..\vsvars32.bat and then enter.
> A message appear is "setting environment for using MS visual studio".
> and then using DEVENV i had build my solution.
"devenv" is a fairly heavyweight way to do that. It basically invokes
the whole IDE. If you are using Visual Studio 2005 or 2008, you can say
which is not quite so heavy as devenv. If you're using an older Visual
Studio, that may not be available.
> can u please help me out that how do i perform above steps in python.
> code snippet is required.
I was going to say "just write the commands out to a temporary batch
file, then call os.system or subprocess.call to run the batch file"
until I read this followup:
a h wrote:
> 1.I want to know how do i write batchfile kind of file in python so
> that it executes some commands. Code snippets are required.
For the future, the way you worded that is impolite. When you say
"required", it is as if you are demanding something from us. It would
be better to say "Please provide code snippets."
> 2.As well how do i invoke command prompt.
> Actually what i need is that i have to perform certain things in
> windows...first i have to go to start->run->type cmd
> then command prompt window is open... in that to run an .exe i have to
> give the whole path like this c:\> cd
> temp_folder\next_folder\test.exe... and many more commands...
> So I want this to be perfomed in python. please help
Can't you just work this out for yourself? You create a file, you write
to it, you run it:
fbat = open( "xxx.bat", "w" )
print >> fbat, "echo I'm inside a batch file"
print >> fbat, 'call "c:\\Program Files\\Microsoft etc\\vsvars32.bat'"
print >> fbat, 'msbuild myproject.sln'
os.system( "xxx.bat" )
os.remove( "xxx.bat" )
Note that you will need extra quotes when the path includes spaces.
Note also the escaped backslash characters.
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the python-win32