从powershell传递批处理文件中的参数

时间:2014-09-03 05:15:11

标签: windows batch-file

我在Windows中创建了一个批处理文件。该文件中的内容是这样的

test.bat的

echo %1

现在,当我从命令行发送一个参数时,就像这样

test.bat "hello"

然后它始终输出%1。它应该是hello

我做错了什么?

2 个答案:

答案 0 :(得分:2)

这真的很奇怪 - 你对文件中的内容不正确的假设。这是我的电脑的输出正是你所描述的:

C:\windows\system32>copy con test.bat
echo %1
^Z
        1 file(s) copied.

C:\windows\system32>test.bat hello

C:\windows\system32>echo hello
hello

我怀疑该文件与您描述的内容有所不同

答案 1 :(得分:2)

也许您正在使用power-shell。您需要在bat文件中使用以下内容:

echo $1

这里是将DOS批处理文件转换为Shell脚本

 http://tldp.org/LDP/abs/html/dosbatch.html
相关问题