Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.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
Parameters 如何为batch files.BAT提供参数,并使用System.Shell.execute执行这些参数_Parameters_Batch File_Shellexecute - Fatal编程技术网

Parameters 如何为batch files.BAT提供参数,并使用System.Shell.execute执行这些参数

Parameters 如何为batch files.BAT提供参数,并使用System.Shell.execute执行这些参数,parameters,batch-file,shellexecute,Parameters,Batch File,Shellexecute,我正在为windows开发一个软件,我需要一个函数“System.Shell.execute”一个批处理文件,但我希望它有两个函数(参数) 所以当我执行: objShell.ShellExecute(“file.bat”、“PARAMETER1”、“open”、“2”) 它将运行bat文件中的参数1和viceverca(用于参数2) 我想知道如何配置批处理文件,例如: @ECHO OFF PARAMETER1 :: execute some code here PARAMET

我正在为windows开发一个软件,我需要一个函数“System.Shell.execute”一个批处理文件,但我希望它有两个函数(参数)

所以当我执行:

objShell.ShellExecute(“file.bat”、“PARAMETER1”、“open”、“2”)

它将运行bat文件中的参数1和viceverca(用于参数2)

我想知道如何配置批处理文件,例如:

@ECHO OFF   

PARAMETER1

::     execute some code here

PARAMETER2  

::     execute some code here

(可能是这样吗?

为每个函数使用批标签。只需转到第一批参数指定的标签。每个“函数”都可以访问从
%2
开始的附加参数

@echo off
goto %1

:PARAMETER1
REM execute code here
exit /b

:PARAMETER2
REM execute code here
exit /b

我会让我的脚本有点不同:

@echo off
goto %1
goto :end

:: functions

:PARAMETER1 comment1
REM execute code here
exit /b 0

:PARAMETER2 comment2
REM execute code here
if %ERRORLEVEL%==1 ECHO goto :error
exit /b 0

:error
ECHO Error occurred with arg %1
timeout 10
exit 1

:: end of script
:end
ECHO Finished

您的
goto:end
是死代码,因为如果标签不存在,
goto%1
将导致致命错误。所以这和我的答案没什么不同,只是有点模糊。有多种方法可以在尝试转到之前验证标签-例如,通过使用硬编码标签字符串的IF,或根据
%~f0
查找标签。但是它并没有真正改变主要的概念。你能回答编辑问题吗?你的“设置”命令是错误的。此外,您已将此问题标记为已回答。请您回答编辑问题。@tofran-我不明白您在新的第二个问题中想做什么。还有,这是第二个问题。请删除此问题的编辑,然后提出一个新问题,并提供有关您尝试执行的操作的更多解释。