码迷,mamicode.com
首页 > Windows程序 > 详细

Windows Batch Scripts

时间:2016-04-15 20:14:05      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:

Some simple examples:

simple.bat

@echo off 
set _var1=3
set _var2=5
set /a _result=%_var1%+%_var2% 
echo Result is %_result%                

 

mult.bat

@echo
off if "%1" == "" goto :help if "%2" == "" goto :help set /a result=%1 * %2 echo Result is %result% goto :eof :help echo Usage: mult X Y (Multiply X by Y)

 

power.bat

@echo off
if "%1" == "" goto :help
if "%2" == "" goto :help
set _result=%1
for /L %%G in (2,1,%2) do set /a "_result*=%1"
echo %1 to the power of %2 is %_result%
goto :eof

:help
echo Usage: power X Y (Calculate X to the power of Y.)

 

functions.bat

@echo off
set /p _num1=Number1: 
set /p _num2=Number2: 
call :plusfunc %_num1% %_num2%
call :output
call :subfunc %_num1% %_num2%
call :output
goto :eof

:plusfunc
setlocal
set /a _num1=%1 + %2
endlocal & set _result=%_num1%
goto :eof

:subfunc
setlocal 
set /a result=%1 - %2
endlocal & set _result=%result%
goto :eof


:output
echo Result is %_result%
goto :eof

 

Windows Batch Scripts

标签:

原文地址:http://www.cnblogs.com/roronoa-sqd/p/5396509.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!