Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
File 要设置为变量的批处理用户输入,在脚本末尾检查是否存在,并应用命令_File_Variables_Batch File_Input - Fatal编程技术网

File 要设置为变量的批处理用户输入,在脚本末尾检查是否存在,并应用命令

File 要设置为变量的批处理用户输入,在脚本末尾检查是否存在,并应用命令,file,variables,batch-file,input,File,Variables,Batch File,Input,我想应该是直截了当的,我想是的,但在工作中遇到了一些困难 目标:- 使用各种批处理命令、文件和软件安装程序创建自动安装。为了让用户不必完成安装、设置和忘记,我希望他们在流程开始时从3个选项中进行选择,但只在最后应用,因此他们选择的3个任务中的一个在没有用户输入的情况下完成 这一切都完成了,只是在开始阶段遇到了问题 代码: 用户可以选择3种方式,复制文件并启动软件,不复制文件并启动配置工具,复制文件并运行软件(等待其他准备) 这是上面的开始菜单,您可以看到数字选项“应该”设置了一个变量。设置此选项

我想应该是直截了当的,我想是的,但在工作中遇到了一些困难

目标:- 使用各种批处理命令、文件和软件安装程序创建自动安装。为了让用户不必完成安装、设置和忘记,我希望他们在流程开始时从3个选项中进行选择,但只在最后应用,因此他们选择的3个任务中的一个在没有用户输入的情况下完成

这一切都完成了,只是在开始阶段遇到了问题

代码: 用户可以选择3种方式,复制文件并启动软件,不复制文件并启动配置工具,复制文件并运行软件(等待其他准备)

这是上面的开始菜单,您可以看到数字选项“应该”设置了一个变量。设置此选项后,文件将运行、安装并执行操作,然后结束,它将运行由“开始”菜单选项定义的相应操作,以便

IF exist %end1% GOTO end1
IF exist %end2% GOTO end2
IF exist %end3% GOTO end3
但是,默认情况下,它只会运行第一个选项,而不会检测其他任何内容。理想情况下,如果客户机在开始时按1、2或3,当它结束时,它会进入与启动相应操作相关的菜单选项

:end 1 "copies a file" launches software
:end 2 "starts a program"
:end 3 "copies a file in preparation for some other task"
希望这是有道理的。如果你需要更多信息,请告诉我。我已经搜索过了,但可能没有搜索到正确的东西

如果我尝试回显end1的存在,它说它没有定义。我猜错误级别检查可能会更好,但也很难做到这一点


谢谢…

存在
检查是否存在文件或文件夹。您需要定义

我不确定您是否真的需要设置3个不同的变量(也许您这样做是为了将问题简化为最简单的步骤)。您可以按如下方式对其进行重构:

SET /P "Input=Enter a Number Choice & Press RTN: "
if '%Input%'=='1' set ending=1
if '%Input%'=='2' set ending=2
if '%Input%'=='3' set ending=3
IF %ending% EQU 1 GOTO end1
IF %ending% EQU 2 (GOTO end2) ELSE (GOTO end3)

:end1
echo ending 1
pause

:end2
echo ending 2
pause

:end3
echo ending 3
pause

这个代码对我有用

假设
end1、end2、end3
在批处理的其他地方定义为文件夹路径,请尝试以下操作:

@echo off
set "mes1=Enter a Number Choice and Press RTN"
choice /c 123 /m "%mes1%" /t 10 /d 1
if %errorlevel% equ 3 (set disk=end3
) else if %errorlevel% equ 2 (set "disk=end2
) else (set disk=end1)

if exist "%disk%" (
   if %disk%==%end1% (goto :end_1
   ) else if %disk%==%end2% (goto :end_2
   ) else if %disk%==%end3% (goto :end_3)
::some code here

:end_1 rem "copies a file" launches software
:end_2 rem "starts a program"
:end_3 rem "copies a file in preparation for some other task"
SET /P "Input=Enter a Number Choice & Press RTN: "
if '%Input%'=='1' (set ending=1
) else if '%Input%'=='2' (set ending=2
) else if '%Input%'=='3' (set ending=3)
if defined ending (GOTO :process%ending%) else (goto :end)
:: put some code here

:process1 rem "copies a file" launches software
:process2 rem "starts a program"
:process3 rem "copies a file in preparation for some other task"

:end
timeout 5 >nul
exit /b
如果不使用驱动器路径,请尝试以下操作:

@echo off
set "mes1=Enter a Number Choice and Press RTN"
choice /c 123 /m "%mes1%" /t 10 /d 1
if %errorlevel% equ 3 (set disk=end3
) else if %errorlevel% equ 2 (set "disk=end2
) else (set disk=end1)

if exist "%disk%" (
   if %disk%==%end1% (goto :end_1
   ) else if %disk%==%end2% (goto :end_2
   ) else if %disk%==%end3% (goto :end_3)
::some code here

:end_1 rem "copies a file" launches software
:end_2 rem "starts a program"
:end_3 rem "copies a file in preparation for some other task"
SET /P "Input=Enter a Number Choice & Press RTN: "
if '%Input%'=='1' (set ending=1
) else if '%Input%'=='2' (set ending=2
) else if '%Input%'=='3' (set ending=3)
if defined ending (GOTO :process%ending%) else (goto :end)
:: put some code here

:process1 rem "copies a file" launches software
:process2 rem "starts a program"
:process3 rem "copies a file in preparation for some other task"

:end
timeout 5 >nul
exit /b

好吧,我一直在摆弄,这是有效的:

SET /P "Input=Enter a Number Choice & Press RTN: "
if '%Input%'=='1' set ending=1
if '%Input%'=='2' set ending=2
if '%Input%'=='3' set ending=3

~things happen~

color 1f
IF %ending% EQU 1 GOTO end1
IF %ending% EQU 2 (GOTO end2) ELSE (GOTO end3)

所有三个菜单选项都正常工作

如果定义了end1转到end1
等。尝试了此操作后,选择了选项3,它只是打开了1它不起作用,因为您使用了
:end 1
而不是明显的
:end1
。如果“%input%”=“1”,是否有特定的原因使用变量而不是
goto:end1
?Hi正在寻找一种方法来设置答案选项,以便在其他命令运行后使用。谢谢你的建议。