[英]Pulling text from a .txt file to insert into a batch file to run an exe
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"
示例:
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. 程序使用m:之后的内容作为我需要的零件号。 It also uses what comes after T: for the drive letter I want to copy to.
它还将T:之后的内容用作要复制到的驱动器号。 I want to be able to choose if the v (validate) is inserted.
我希望能够选择是否插入v(验证)。 I want to choose if the l (logfile) is inserted.
我想选择是否插入l(日志文件)。
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"
因此,我需要的是一种将变量信息插入批处理文件并使用开关EX运行.exe文件的方法:
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: 正如Squashman在其评论中已经指出的那样,您不需要文件:
@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 这将允许您以thisbatch 1234 dy mylogfilename的身份运行
or simply as thisbatch 1234 或简称为thisbatch 1234
to default to drive D
with no verify and no logfile. 默认为没有验证且没有日志文件的驱动器
D
I misread that you wanted y
to specify logfile = logfile.txt 我误读了您要
y
指定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" 在
run
子例程的“ logfile.txt
”处,应将其转换为“如果最后一个参数为y,则使用logfile.txt
”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.