如何将参数传递给已在单独文件(如配置文件)中定义的批处理脚本。
我是批处理脚本并尝试学习的新手。任何帮助表示赞赏
答案 0 :(得分:0)
在批处理中,参数被引用为%1
,第一个引用为%9
%0
引用正在运行的批处理文件的名称
%*
引用“所有参数”
有一些修饰符可以获得你想要的部分。请参阅here和call /?
快速展示这个概念:
使用以下批处理文件尝试此命令行:
test.bat "C:\my folder\subfolder\test.txt" hello world
批处理文件:
@echo off
echo this file: %0
echo this full qualified file name: %~f0
echo drive for this file: %~d0
echo path for this file: %~p0
echo this filename: %~n0
echo this file's extension: %~x0
echo param1: %1
echo full qualified file name: %~f1
echo drive: %~d1
echo path: %~p1
echo filename: %~n1
echo extension: %~x1
echo param 2: %2
echo param 3: %3
echo all parameters: %*