سؤال

I am developing a software for windows and there is a function that I need to “System.Shell.execute” a batch file but I want it to have two functions (parameters)

So when I execute:

objShell.ShellExecute("file.bat", "PARAMETER1", "", "open", 2);

it will run the PARAMETER1 in the bat file, and viceverca (for parameter2).

I want to know how i can configure my batch file to do that, Ex:

@ECHO OFF   

PARAMETER1

::     execute some code here

PARAMETER2  

::     execute some code here

(is possible something like that?)

هل كانت مفيدة؟

المحلول

Use a batch label for each function. Simply GOTO the label specified by the 1st batch parameter. Each "function" can access additional parameters starting with %2.

@echo off
goto %1

:PARAMETER1
REM execute code here
exit /b

:PARAMETER2
REM execute code here
exit /b

نصائح أخرى

I would make my script a little different:

@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
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top