windows批处理
2022-05-25 22:18
821 查看
1.批处理以及它的作用
1.微软系统自带的原生开发语言,不需要构建任何开发环境就可以执行的脚本。 2.可以匹配文件。新建文件日志这些 3.编写一些可以被windows执行的脚本,例如编译解决方案,或者安装windows服务。卸载windows服务
2.输出Hello World//关闭命令显示 @echo off echo Hello World pause3.常用批处理实践
1.安装.net开发的windows服务
@echo off color 0a set Filename=Source\Applications\RDA\RAD.Module.Synchronizer\RDA.Module.Synchronizer\bin\Debug\STAr.Aquarius.RDA.Module.Synchronizer.exe set Servicename= Windows Synchronizer set Frameworkdc=%SystemRoot%\Microsoft.NET\Framework\v3.5 if exist "%Frameworkdc%" goto netOld :DispError echo .Net Framework 3.5 is not installed on your machine, the installation will be terminated soon.. echo .Net Framework 3.5 is not installed on your machine, the installation will be terminated soon. >InstallService.log goto LastEnd :netOld cd %Frameworkdc% echo The corresponding .net Framework 3.5 is installed on your machine, you can install this service. echo The corresponding .net Framework 3.5 is installed on your machine, you can install this service >InstallService.log echo. echo. >>InstallService.log echo "%Filename%">1.txt C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe %~dp0\"%Filename%" net start SendSms echo ----------------------------- echo Service installed successfully echo ----------------------------- pause
2.调用msbuild编译解决方案
3.windows 服务附加调试
3.批处理运算操作1.算术运算
1.* / % + - (命令模式:cmd输入 "set /a 1+2")
2.括号改变执行优先级 (文本模式:先要定义变量接收结果,然后用%号包裹输出变量值)
2.重定向运算
-
-
使用> 符号 结果会覆盖原有内容
-
-
使用>> 符号追加到已有内容后面
@echo off set /a tmp=10+2 echo %tmp% > put.txt set /a tmp_1 = 10*20 echo %tmp_1% >> put.txt
3.多命令运算
-
-
使用&&符号 &&之前的命令执行错误就不会执行 && 后面的内容
-
-
使用|| 第一个执行错误会执行第二个
4.管道符号 A|B
将第一个参数的结果作为第二个参数的输入
- 1.假设a文件夹下有b和c文件夹,1.txt和2.txt文件,查找以txt后缀结尾的文件,并输出到tmp.txt文件中
@echo off dir | find ".txt" > tmp.txt pause
- 2.查找当前主机和其他地址建立网络连接的内容,并输出到tmp.txt文件中
@echo off netstat -an | find "ESTABLISHED" > tmp.txt pause
4.批处理文件参数传递
%1 代表第一个参数,%2代表第二个参数,参数之间用空格隔开,例如有一个test.cmd批处理,跳转到所在目录然后执行test.cmd 参数1 参数2 就可以调用这个批处理输出 用户输入的2个参数值
@echo off echo %1 echo %2 pause @rem 执行这个批处理文件 test.cmd 参数1 参数24.基本命令
- 1.
goto
流程控制转向
@echo off echo 使用goto命令 goto last set tmp="Hello World" echo %tmp% @rem 设置跳到的标识 :last echo 跳过命令之后执行的语句 pause
- 2.
start
重新启用一个单独的命令窗口,然后在新窗口执行指定命令-
start ["Title"] 设置命令窗口的标题
-
-
start /max & /min 设置命令窗口最大最小化
-
-
start /wait 等待新窗口执行结束
start /max @echo off echo 使用start命令 @rem 开始一个新的程序窗口,标题为new window 等待新窗口执行 在新窗口执行输出New window start 'new window' /wait echo new window echo pause
3.
if
逻辑控制命令-
if exist & if not exist 条件为真或为假
-
-
if string==string () else ()
-
-
if number==number () else ()
-
-
if /i A==a (echo 123) else echo 234 忽略大小写
start /max @echo off echo use if command @rem if exist a.txt (echo find file) else (no find) pause
相关文章推荐
- Windows批处理命令与用法
- Windows批处理调用程序后如何自动退出
- Windows批处理 实现数组方法
- Windows批处理修改文件名
- WINDOWS批处理命令详解(转)
- Windows批处理生成目录树
- windows批处理命令大全
- windows批处理(cmd/bat)编程详解
- windows批处理(cmd/bat)编程详解
- 以程序设计语言角度看windows批处理
- Windows批处理命令教程
- Windows批处理:自动检查服务器连通性
- 实现windows批处理下的计时功能
- Windows批处理(cmd/bat)常用命令小结
- windows批处理脚本
- windows批处理基础练习(学习Ing)
- 【264】Windows批处理
- Windows批处理(bat)call和start的区别
- Windows批处理常用
- Windows批处理功能配合脚本还是很强大的!(3)