tags:

views:

49

answers:

4

I'm would like to know how I can open a specific file using a specific program with a batch file. So far, my batch file can open the program, but I'm not sure how to open a file with that program.

@echo off
start wgnuplot.exe
+2  A: 
start wgnplot.exe "c:\path to file to open\foo.dat"
Chris Thornton
This worked like a charm, except when I run the batch file, GNUPlot flickers on the screen and then shuts off immediately. I tried adding "pause" to the batch file but that didn't do anything.
Soo
Try this: go to a command prompt, and see if you can get it to work. i.e. don't try to program it into a .bat file until you are certain of how to run the program and what params it expects.
Chris Thornton
+1  A: 
@echo off
start %1

or if needed to escape the characters -

@echo off
start %%1
Etamar L.
+1  A: 

That program would need to have a specific API that you can use from the command line.

For example the following command uses 7Zip to extract a zip file. This only works as 7Zip has an API to do this specific task (using the x switch).

"C:\Program Files\7-Zip\CommandLine\7za.exe" x C:\docs\base-file-structure.zip 
Marcus
+1  A: 

You can simply call

program "file"

from the batch file for the vast majority of programs. Don't mess with start unless you absolutely need it; it has various weird side-effects that make your life only harder.

The The point here is that pretty much every program that does something with files allows passing the name of the file to do something with in the command line. If that weren't the case, then you couldn't double-click files in the graphical shell to open them, for example.

If the program you're executing is a console application, then it will run in the current console window and the batch file will continue afterwards. If the program is a GUI program then the batch file will continue immediately after starting it.

Joey