Windows batch脚本总结

        不得不说Windows batch脚本是我见过的最差劲的脚本,没有之一。

        先上一段最近解决的几个小问题的demo代码,包括:

        1,赋值变量为其他进程的输出

        2,For循环语句计算数列

        3,For循环拆分字符串

        4,For循环处理文件

        5,For循环处理进程输出

@echo off
setlocal enabledelayedexpansion

:: set a variable using the output of process
tasklist | findstr "explorer.exe" > result.txt
set /p FF=<result.txt
echo %FF%

:: for statement in numbers
set total=0
for /l %%i in (1,1,5) do (
set a=%%i
echo !a!
set /a total=!total! + !a!
)
echo total=%total%

:: for statement in strings
for /f "tokens=1,2* delims=_" %%i in ("test_argument_12345") do (
 echo %%i
 echo %%j
 echo %%k
)

:: for statement using wildcard, shouldn't use /f option
for %%G in (*.bat *.txt) do echo %%G

:: for statement in files
for /f "tokens=1,2*" %%i in (result.txt) do (
set ti=%%i
echo !ti!
echo %%j
echo %%k
)

:: for statement with command output
for /f "tokens=1,2*" %%i in ('"tasklist | findstr "explorer.exe""') do (
set ti=%%i
echo !ti!
echo %%j
echo %%k
)
endlocal


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值