简体   繁体   中英

Pass parameters in batch file from powershell

I have made a batch file in Windows. The content in that file is like this

test.bat

echo %1

Now when I send an argument from command line like this

test.bat "hello"

then it outputs always %1 . It should be hello .

What I am doing wrong?

This is really odd - something in your assumptions about what is in the file is not correct. Here is the output from my pc doing exactly what you describe:

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

I suspect the file has something different in than what you describe

Perhaps you are using power-shell. you need to use the following in your bat file:

echo $1

Here is Converting DOS Batch Files to Shell Scripts

 http://tldp.org/LDP/abs/html/dosbatch.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM