Reputation: 23177
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
Upvotes: 16
Views: 241388
Reputation: 354356
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 (i.e. not a console program; that's a distinction in the EXE) then the batch file will continue immediately after starting it.
Upvotes: 1
Reputation: 1
If you are trying to open a file in the same directory it would be:
./PROGRAM TRYING TO OPEN
./FILE NAME/PROGRAM TRYING TO OPEN (or this)
Or, if trying to backtrack from the same directory it would be:
../PROGRAM TRYING TO OPEN
../FILE NAME/PROGRAM TRYING TO OPEN (or this)
Else, if you need a straight one from start, it would be:
(DIRECTORY TYPE)\Users\%username%\(FILE DIRECTORY)
(ex) C:\Users\ajste\Desktop\Henlo.cmd
Upvotes: 0
Reputation: 1
@echo off
cd "folder directory to your file"
start filename.ext
For example:
cd "C:\Program Files (x86)\Winamp"
Start winamp.exe
Upvotes: 0
Reputation: 101
you are in a situation where you cannot set a certain program as the default program to use when opening a certain type of file, I've found using a .bat file handy. In my case, Textpad runs on my machine via Microsoft Application Virtualization ("AppV"). The path to Textpad is in an "AppV directory" so to speak. My Textpad AppV shortcut has this as a target...
%ALLUSERSPROFILE%\Microsoft\AppV\Client\Integration\
12345ABC-A1BC-1A23-1A23-1234567E1234\Root\TextPad.exe
To associate the textpad.exe with 'txt' files via a 'bat' file:
1) In Explorer, create a new ('txt') file and save as opentextpad.bat in an "appropriate" location
2) In the opentextpad.bat file, type this line:
textpad.exe %1
3) Save and Close
4) In explorer, perform windows file association by right-clicking on a 'txt' file (e.g. 'dummy.txt') and choose 'Open with > Choose default program...' from the menu. In the 'Open with' window, click 'Browse...', then navigate to and select your textpad.bat file. Click 'Open'. You'll return to the 'Open with' window. Make sure to check the 'Always use the selected program to open this type of file' checkbox. Click 'OK' and the window will close.
When you open a 'txt' file now, it will open the file with 'textpad.exe'.
Hope this is useful.
Upvotes: 2
Reputation: 61
If the file that you want to open is in the same folder as your batch(.bat) file then you can simply try:
start filename.filetype
example: start image.png
Upvotes: 6
Reputation: 56659
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
Upvotes: 1
Reputation: 1162
@echo off
start %1
or if needed to escape the characters -
@echo off
start %%1
Upvotes: 4