views:

6008

answers:

5

This is a batch file in Windows.

Here is my .bat file

@echo off
copy "C:\Remoting.config-Training" "C:\Remoting.config"

"C:\ThirdParty.exe"

This works fine except the .bat file leaves the command window open the whole time the "ThirdParty" application is running.
I need the command window to close.

I would use the short-cut for the application but I must be able to run this copy command first (it actually changes which data base and server to use for the application).

The ThirdParty application does not allow the user to change the source of the db or the application server.

We're doing this to allow users to change from a test environment to the production environment.

A: 

I haven't really found a good way to do that natively, so I just use a utility called hstart which does it for me. If there's a neater way to do it, that would be nice.

Oskar Duveborn
+3  A: 

Try this:

@echo off 
copy "C:\Remoting.config-Training" "C:\Remoting.config"
start C:\ThirdParty.exe
exit
QAZ
Don't use the quotes around C:\ThirdParty.exe and this will work perfectly.
Patrick Cuff
Cool, thanks Patrick.
QAZ
That worked perfectly for me as well, thanks.
sparks
+5  A: 

Using start works for me:

@echo off copy "C:\Remoting.config-Training" "C:\Remoting.config"
start C:\ThirdParty.exe

EDIT: Ok, looking more closely, start seems to interpret the first parameter as the new window title if quoted. So, if you need to quote the path to your ThirdParty.exe you must supply a title string as well.

Examples:

:: Title not needed:
start C:\ThirdParty.exe

:: Title needed
start "Third Party App" "C:\Program Files\Vendor\ThirdParty.exe"
cg
Now the Thirdparty app doesn't start and my command window stays open.
Jeff O
Yes, you're right. When I used this I did not quote the path to my application. Please have a look at my revised answer.
cg
Thanks to Patrick Cuff for improving my answer. I'm still new to SO and did not realize until now that enough reputation would allow you to edit other people's posts...
cg
A: 

Please use this one, the above does not work. I have tested in Window server 2003. @echo off copy "C:\Remoting.config-Training" "C:\Remoting.config" Start /I "" "C:\ThirdParty.exe" exit

What error did you get indicating the 'above' does not work? Maybe it is because you are using Windows Server?
Jeff O
A: 

Using start works fine, unless you are using a scripting language. Fortunately, there's a way out for Python - just use pythonw.exe instead of python.exe:

:: Title not needed:
start pythonw.exe application.py

In case you need quotes, do this:

:: Title needed
start "Great Python App" pythonw.exe "C:\Program Files\Vendor\App\application.py"
mzuther