简体   繁体   English

运行需要直接从文件夹输入的批处理文件

[英]Running a batch file which requires inputs directly from folder

I have a batch file which requires 4 command line inputs. 我有一个批处理文件,需要4个命令行输入。 When I execute the batch file on the command prompt, it displays help message asking to input 4 values. 当我在命令提示符下执行批处理文件时,它将显示帮助消息,要求输入4个值。

When I run this file directly from the folder, it opens cmd and closes immediately. 当我直接从文件夹运行此文件时,它将打开cmd并立即关闭。

Is it possible to modify the batch file, so that when I run from folder it will open the cmd and then display the help message.? 是否可以修改批处理文件,以便当我从文件夹运行时将打开cmd,然后显示帮助消息。

Following is a mini version of my problem with 1 command input. 以下是我的问题的迷你版本,其中包含1个命令输入。 The script is for a License file generation 该脚本用于生成许可证文件

@ECHO OFF
GOTO :continue

:continue
SETLOCAL
IF "%1" == "" GOTO :Help

::Set the Command Line Options
SET ARVERSION=%1

::Create Directory
SET OUT_PATH=%cd%

ECHO  Initiating Generation...

if not exist %OUT_PATH% mkdir %OUT_PATH%

::Create License File - Calling 'Subs' will create the output with actual Version
Subs ARVERSION %ARVERSION% Input.txt 1>%OUT_PATH%\License.txt

ECHO Scripts are created @ %OUT_PATH%
ECHO  Generation Completed...

GOTO :End

:Help
ECHO  Starting License File Generation...
ECHO Usage:
ECHO InstallerScriptGen.bat AR_VERSION
ECHO AR_VERSION            - Version (3.2 or 4.0 or 4.2)
ECHO Example : InstallerScriptGen.bat 3.2.2
ECHO Please Note that input of incorrect values will result in wrong generation.

:End
ENDLOCAL

"Running directly from the folder" (by which I assume you mean "clicking on the icon from within Windows Explorer") causes Windows Explorer to execute the equivalent of CMD /C <<batchfilename>> . “直接从文件夹运行”(我假设您的意思是“从Windows资源管理器中单击图标”)使Windows资源管理器执行等效于CMD /C <<batchfilename>> When invoked with /C , CMD exits (and the CMD window closes) as soon as the batch file ends. /C调用时,批处理文件结束时, CMD退出(并且CMD窗口关闭)。 You can force the window to stay open long enough to read the output by ending the script with either the PAUSE command (which will cause it to wait for the user to press any key), or the TIMEOUT command (which will wait the indicated number of seconds before continuing, without a keypress). 您可以通过以下方式强制窗口保持打开状态足够长的时间以读取输出:使用PAUSE命令(这将使其等待用户按任意键)或TIMEOUT命令(将等待指示的数字)结束脚本持续几秒钟,无需按键)。 See SS64's help for the PAUSE and TIMEOUT commands for more information. 有关更多信息,请参见SS64的PAUSETIMEOUT命令帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM