Windows CMD Start and wait for the default application in a batch file -
i trying start default application file, wait complete, , continue batch file. problem start, when used below creates command prompt window example.doc in title bar. can use call instead of start, call not wait program finish before going next line. appears start needs have executable name , not work default application system in windows.
any ideas how can make happen without having hardcode windows application in batch file well?
set filename=example.doc start /wait %filename% copy %filename% %filename%.bak
how start default application file, wait completion, continue?
it appears start needs have executable name , not work default application system in windows.
start
, when used below creates command prompt window example.doc in title barstart /wait %filename%
the above command won't work because %filename%
used window title instead of command run.
always include title can simple string
"my script"
or pair of empty quotes""
according microsoft documentation, title optional, depending on other options chosen can have problems if omitted.
source start
try following command instead:
start "" /wait %filename%
alternative solution using default open command
any ideas how can make happen without having hardcode windows application in batch file well?
one way use assoc
, ftype
default open command used file execute command.
the following batch file (so no hard coding of windows applications needed).
open.cmd:
@echo off setlocal enabledelayedexpansion set _file=example.doc rem extension %%a in (%_file%) ( set _ext=%%~xa ) rem filetype associated extension /f "usebackq tokens=2 delims==" %%b in (`assoc %_ext%`) ( set _assoc=%%b ) rem open command used files of type filetype /f "usebackq tokens=2 delims==" %%c in (`ftype %_assoc%`) ( set _command=%%c rem replace %1 in open command filename set _command=!_command:%%1=%_file%! ) rem run command , wait finish. start "" /wait %_command% copy %_file% %_file%.bak 1>nul endlocal
further reading
- an a-z index of windows cmd command line - excellent reference things windows cmd line related.
- assoc - display or change association between file extension , filetype
- enabledelayedexpansion - delayed expansion cause variables expanded @ execution time rather @ parse time.
- for - conditionally perform command several times.
- for /f - loop command against results of command.
- ftype - display or change link between filetype , executable program.
- start - start program, command or batch script (opens in new window).
- variable edit/replace - edit , replace characters assigned string variable.
Comments
Post a Comment