I want pass specific parameters(aaa|bbb|ccc) but it's not working.
Here's what the command line looks like:
test.bat aaa|bbb|ccc
and test.bat looks like:
echo %1
but its not working cuz test.bat receive only 'aaa'.
how can I pass whole parameter 'aaa|bbb|ccc'?
ps. I must use this format : 'aaa|bbb|ccc'
there is no option to change like aaa_bbb_ccc.. etc.
Using the "|" means you use the pipe function.
http://ss64.com/nt/syntax-redirection.html
You should use "aaa|bbb|ccc" so that it will read everything between the quotation marks.
I hope it helps
The VERTICAL BAR is the pipe character to command.com and cmd.exe. If you want to use is literally, it must be escaped using a CARET.
K:>echo aaa^|bbb^|ccc
aaa|bbb|ccc
Actually, I think I might prefer the quoting suggestion as it appears to work under bash and perhaps other shells.
$ echo "aaa|bbb|ccc"
aaa|bbb|ccc
$ echo 'aaa|bbb|ccc'
aaa|bbb|ccc
Related
I have a batch file that copies and moves stuff, but I am getting stuck dealing with Certificates. I have to use a command the vendor provides called installrootcacert.cmd, but I also need to pass the file name of the cert which is aptly named rootca.cer. I have to use the script the vendor provides so there is no way around that.
Normally I would run this from the command like like so:
c:\vendor\Software\Conf\Security\installrootcacert.cmd rootca.cer
I have attempted to call the command from my batch file, but with no luck.
I tried to use a variable, but because that command calls several other processes, it is looking for "rootca.cer" after the command. If I place it in a variable, the other processes fail. I cannot modify the other processes.
echo #off
cd E:\vendor\Software\Conf\Security\trustedCA
e:
call "e:\vendor\Software\Conf\Security\installrootcacert.cmd rootCA.cer"
A possible solution, might be:
#echo off
cd /d "E:\vendor\Software\Conf\Security\trustedCA"
call "E:\vendor\Software\Conf\Security\installrootcacert.cmd" rootCA.cer
echo #off replaced with #echo off because echo #off will echo #off in cmd.
It is mentioned by Compo in comments, you are changing drives: use /d option with cd.
Finally, quote only the filename in the call command, else, windows will interpret this as a complete filename (i.e. E:\vendor\Software\Conf\Security\installrootcacert.cmd rootCA.cer, so filename will be installrootcacert.cmd rootCA.cer).
Try the following. You need to adjust the # in your echo statement and your quotations:
#echo off
cd E:\vendor\Software\Conf\Security\trustedCA
e:
call "e:\vendor\Software\Conf\Security\installrootcacert.cmd" rootCA.cer
The reason that this works is because putting the command #echo off in your script stops ALL commands from being output. If you just have echo #off, you're literally going to echo that. (credit to double-beep for initially suggesting that)
As for the quotes, what you are trying to do is pass that as a command, so when you call the rootCA.cer, you need to make sure you are passing it the proper parameters, which is why you place that filepath in quotes. If you place the WHOLE object in quotes, you aren't actually issuing a call to the rootCA.cer command. (credit to LotPings for initially suggesting that).
I have a text file with lots of commands in it and I want to sent those commands to a software called thermocal. It is a console application. I found the command below, but it doesn't work for me.
Do I need to put this .exe file in the same folder of the batch file to make it work or any thing else?
type somefile.txt | Thermocal.exe
Batch scripts can be considered as a collection of lines you could also type in a command line prompt one after another. With respect to this it might be helpful for you, to play with cmd in order to get a feeling for what is happening.
About starting thermocal: Assuming thermocal is not part of PATH then the batch file either needs to change the current directory to the one with termocal.exe. Alternatively you might be able to call thermocal.exe with adding a path like C:\ProgramFiles\Thermocal\thermocal.exe . Play with cmd to find out, what works and what doesn't
When you are able to start thermocal from the command line prompt window, you can start experimenting with the call. You will probably end of with something like this in your command line window:
C:\ProgramFiles\Thermocal> thermocal argument1 argument 2
If this works, you can start with batch programming :)
Assuming your arguments are stored in somefile.txt like this:
argument1 argument 2
TYPE does nothing more than printing a file:
TYPE somefile.txt
Now you need to use the result of the output as command line arguments:
for /f %%i in ('type somefile.txt') do (thermocal.exe %%i)
Hello stackoverflow users!
I'm not really new to batch. I just never used pipes | in batch and even after I read reference on ss64.com I don't understand what's the pipe used for.
At first I thought it is OR operator or something (obviously I know now it's not).
I only know that it's located between two lines (commands) like &, but I still don't get what it does exactly, and how it is used practically in code.
Thanks for answering!
Pipe [|]: Redirect standard output of commandA to standard input of commandB
http://www.robvanderwoude.com/redirection.php
example :
echo KKZiomek | find "KKZ"
will redirect the echo KKZiomek in the input of the FIND and be used as second parameter of it.
Like well commented by #aschipfl the space is piped too.
so better use :
echo KKZiomek| find "KKZ"
The pipe is used to send the output of one command to the input of another command.
For example, del /p will ask for confirmation when you delete files. However, you can pipe echo y to it to send a y to the del command and del will act as if the user had pressed y.
I am trying to write a batch file in windows, where "%0" needs to be understood as "%0" instead of the name of the batch file. How can I achieve this?
Thanks!
You may use the "escape" trickery, whereby %, preceded by another %, will be treated like a literal:
%%0
Sorry... Just googled it.
Use double percent signs.
"%%0" will be fine.
I want to invoke a batch file(tomcat's startup.bat) by passing a command line argument something like c:>startup.bat -Dsun.lang.ClassLoader.allowArraySyntax=true
But the "=" symbol is being replaced with a space.
If I put c:>startup.bat -D"sun.lang.ClassLoader.allowArraySyntax=true" the value was not set properly.
I am using Windows 7.
Is there anyway to pass command line arguments containing "="?
Thanks,
Siva
You can't do much about it inside the batch file, except change %1 to %1=%2, which only works if you know exactly how many parameters you're passing in, or you know they will always come in pairs. (I suppose you could loop and put together all of the -Dxxx parameters with the next parameter, and put those without a leading -D, but if you have other =-style parameters it can get really messy.)
But you can do something outside the batch file, by putting your parameter in quotes:
startup "-Dsun.lang.ClassLoader.allowArraySyntax=true"
You can use %* for all parameters.
In your batch
#echo off
javac %*
Or you can enquote your complete parameter
startup.bat "-Dsun.lang.ClassLoader.allowArraySyntax=true"
And startup.bat looks like (the %~1 removes surrounding quotes from %1)
#echo off
javac %~1