windows – 如何从第N个位置获取批处理文件参数?
发布时间:2020-12-13 20:18:19 所属栏目:Windows 来源:网络整理
导读:进一步到 How to Pass Command Line Parameters in batch file如何通过指定它们得到其余的参数?我不想使用SHIFT,因为我不知道可能有多少个参数,并且想避免计数它们,如果可以的话. 例如,给定此批处理文件: @echo offset par1=%1set par2=%2set par3=%3set t
进一步到
How to Pass Command Line Parameters in batch file如何通过指定它们得到其余的参数?我不想使用SHIFT,因为我不知道可能有多少个参数,并且想避免计数它们,如果可以的话.
例如,给定此批处理文件: @echo off set par1=%1 set par2=%2 set par3=%3 set therest=%??? echo the script is %0 echo Parameter 1 is %par1% echo Parameter 2 is %par2% echo Parameter 3 is %par3% echo and the rest are %therest% 运行mybatch opt1 opt2 opt3 opt4 opt5 … opt20将产生: the script is mybatch Parameter 1 is opt1 Parameter 2 is opt2 Parameter 3 is opt3 and the rest are opt4 opt5 ...opt20 我知道%*给出了所有的参数,但是我不会先前三个(例如).
不用使用SHIFT就可以做到这一点:
@echo off for /f "tokens=1-3*" %%a in ("%*") do ( set par1=%%a set par2=%%b set par3=%%c set therest=%%d ) echo the script is %0 echo Parameter 1 is %par1% echo Parameter 2 is %par2% echo Parameter 3 is %par3% echo and the rest are %therest% (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- Microsoft Team System和Java
- compact-framework – Windows Ce 6.0上的Compac
- windows – Internet Explorer 8在哪里存储其故障
- windows-server-2003 – IIS 6.0上的HTTP压缩(Wi
- winapi – 调用Win32函数在Lua中返回带外星人的字
- xaml – WP7中更厚的ProgressBar,怎么样?
- 如何防止我的.Net dll被添加为参考?
- active-directory – 修复错误,确定在域控制器升
- windows-server-2008 – 在Windows Server 2008
- 为什么以及什么时候需要mqtt经纪人用于IOT / M2M
热点阅读