Im very new to this and would love some help.
Im trying to run a program in command line but i need to add a drive letter that changes and a part number that also changes. example: start "" "U:\\ISO\\fileTool\\file_Update.exe /m:(PARTNUMBER) /t:(DRIVELETTER) /v /l:logfile.text"
The program uses what is after m: for the part number I need. It also uses what comes after T: for the drive letter I want to copy to. I want to be able to choose if the v (validate) is inserted. I want to choose if the l (logfile) is inserted.
As part of the prep I have a batch file to ask the user for the part number, drive letter, if they want to validate and if they want a log file. The output of that is a text file that looks like this without the information in the brackets
text file output:
Variable One = 1234 (partnumber)
Variable Two = D (Driveletter)
Variable Three = Y (validate could be N to exclude)
Variable Four = Y (logfile could be N to exclude)
So what i need is a way to have the variable information inserted into the batch file and run the .exe file with the switches EX: start "" "U:\\ISO\\fileTool\\file_Update.exe /m:12345 /t:m /v /l:logfile.txt"
As Squashman already noted in his comment, you don't need a file:
@echo off
set /p "VarOne=Enter Part Number: "
set /p "VarTwo=Enter Drive Letter: "
set /p "VarThree=Enter Validate? Y/N: "
if /i "%VarThree%"=="Y" (set "VarThree=/v") else (set "VarThree=")
set /p "VarFour=Use Log File? Y/N: "
if /i "%VarFour%"=="Y" (set "VarFour=/l:logfile.txt") else (set "VarFour=")
start "" "U:\ISO\fileTool\file_Update.exe" /m:%VarOne% /t:%VarTwo% %VarThree% %VarFour%
@ECHO OFF
SETLOCAL
CALL :run %*
:loop
SET "input="
SET /p "input=Part[,Drive[,Verify[,Logfile]]]"
IF DEFINED input CALL :run %input%&GOTO loop
GOTO :EOF
:run
FOR %%a IN (logfile verifyp) DO SET "%%a="
IF "%~4" neq "" SET "logfile=/l:%~4"
IF /i "%~3" equ "Y" SET "verifyp=/v"
IF /i "%~2" equ "" (SET "drive=D") ELSE (SET "drive=%~2")
ECHO(start "" "U:\ISO\fileTool\file_Update.exe /m:%~1 /t:%drive% %verifyp% %logfile%"
GOTO :EOF
This would allow you to run as thisbatch 1234 dy mylogfilename
or simply as thisbatch 1234
to default to drive D
with no verify and no logfile.
I misread that you wanted y
to specify logfile = logfile.txt
IF /i "%~4" equ "y" SET "logfile=/l:logfile.txt"
in plac of the "~4" processing in the run
subroutine should convert that to "use logfile.txt
if last parameter is y"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.