call ant script in windows cmd with parameters and redirect output - batch-file

I'm trying to call a windows cmd script that runs ant with a variable number of parameters and redirect the output to a logfile. The reason why I call the script that runs ant is because then I ant returns the control the my calling script in which I can proceed with other stuff. My call fails on the redirect at the end, it looks like the redirect is seen as a parameter.
The call look like this:
call ant_call ant -buildfile %BUILDDIR%\cadis\cm\build.xml -Dcvs.tag=%1 deploy_cmdscripts >> %LOGFILE% 2>&1
Since I have an unknown number of parameters the ant script looks like this
%1 %2 %3 %4 %5 %6 %7 %8 %9
Is there an easy way to solve this?

Use %* instead of %1 %2 %3 %4 %5 %6 %7 %8 %9.
%* contains all parameters from the command line, even more than nine.

Related

FOR LOOP in windows cmd and batch file not working

I am trying to call a batch file that runs a for loop and calls a second script:
for /f "usebackq" %%i in (`dir/b /o:d %partionHome%\tmp\queue\*.t~#`) do %partitionHome%\conf\SQLLoader\SQL_Loader_%DSNname%\Script.bat %1 %2 %3 %4 %5 %6 %7 %%i %has_prefix% %partionHome%
Script.bat never runs; I've tried adding do call but i believe this gets ignored with FOR /F, I just cannot get the loop to call the script. All parameters are available and paths etc. are correct?
The DIR command is probably not returning anything, so there is nothing for FOR /F to iterate.
Looks to me like you have a spelling mistake: %partionHome% vs. %partitionHome%.
Also, make sure your variables partitionHome and DSNname are defined properly.
The CALL is definitely needed (once you fix the other problems)
Lastly, you should enclose your paths in quotes, just in case there are spaces and/or poison characters within the value.
for /f "usebackq" %%i in (`dir/b /o:d "%partitionHome%\tmp\queue\*.t~#"`) do call "%partitionHome%\conf\SQLLoader\SQL_Loader_%DSNname%\Script.bat" %1 %2 %3 %4 %5 %6 %7 "%%I" %has_prefix% "%partitionHome%"

Set command puts all parameters into %1 %2 %3 etc

A few years back I remember using a set command that would take a variable separated by spaces that would assign each value to %1 %2 %3 etc
I read a line from a file which has the following structure
"log file" "B:\Current\log" "B:\Backup\warehouse" "Warehouse_Day"
and assign it to a variable lets say params, then do the infamous set command params, and then automagically I could use each parameter independently.
If I did echo %1, I would get log file
if I did echo %2, I would get B:\Current\log
if I did echo %3, I would get B:\Backup\warehouse
Does anyone remember or know what the command was?
When I understand you right, this is what you think of:
#echo off
set /p "params="<params.bat
echo %params%
call :program %params%
echo %1, %2, %3, %4 are gone.
echo --%param4%--
goto :eof
:program
echo %1
echo %2
echo %3
echo %4
set param4=%4
Of course the %n parametes are only valid within the called subroutine and are gone, when you return from the subroutine (but you can derive other variables from them).
If you need to get rid of the quotes, use %~1, %~2 and so on.

batch file - pop up with optional arguments

First time poster.
I use a program called PDW. It scans pager frequencies and displays pager messages on the screen.
One of the functions is that it can run a batch or COM file when it pics up a message to a specific pager.
It also has the function to be able to pass through "optional arguments" to the batch or COM file.
.
This is what it says in the help document of the program;
Command file
The command file lets you run an external program file (with optional arguments) when
you receive a filter match and the filter has the “Enable filter command file” enabled.
This program file can be any executable file or a “.BAT” or “.COM” file.
“Browse” lets you browse for a filename, or you can just type in a filename directly.
In the “arguments” control you can enter the arguments to be passed to the command
file.
These can be anything you like or any of these special character sequences :
%1 Address
%2 Time
%3 Date
%4 Mode
%5 Type
%6 Bitrate
%7 Message
%8 Label
For example : “%1” “%2” “%3” “%7” will expand to something like :
1234567 15:21:44 01-02-10 This is a TEST message
Currently I have the following batch file set up (found on stackoverflow), which creates a popup but does not display the optional arguments...
>#echo off
echo code=Msgbox(" ALERT!", vbYesNo, "TRIGGER ALERT") > "%temp%\popupBox.vbs"
echo WScript.Quit code >> "%temp%\popupBox.vbs"
cscript /nologo "%temp%\popupBox.vbs"
if %errorlevel%==6 call :ok_tag
if %errorlevel%==7 call :cancel_tag
echo Done!
exit /b 1
:ok_tag
echo You pressed Yes!
exit /b
:cancel_tag
echo You pressed No!
exit /b
What I want to do, is have a file that not only creates a pop up on my screen, but also can receive these optional arguments from the program (Specifically %1 Address, %2 Time, %3 Date, and %7 Message).
So can anyone help me with a code that will do what I want?
This change should give you extra info in the popup
echo code=Msgbox(" %~1 - %~2 - %~3 - %~7 ", vbYesNo, "TRIGGER ALERT") > "%temp%\popupBox.vbs"

How to pass multiple parameters in CMD to batch file

i dont get it. I would like to pass multiple parameters to a batch file, that has the following description:
When passing parameters instead the first parameter (%1) should be PARAM and the
other parameters are shown in the list.
%epin% or %1 contains the file with full path and no extensions for input files
%epout% or %2 contains the file with full path and no extensions for output files
%epinext% or %3 contains the extension of the file selected from the EP-Launch
program. Could be imf or idf -- having this parameter ensures that the correct user
selected file will be used in the run.
%epwthr% or %4 contains the file with full path and extension for the weather file
%eptype% or %5 contains either "EP" or "NONE" to indicate if a weather file is used
%pausing% or %6 contains Y if pause should occur between major portions of
batch file
%maxcol% or %7 contains "250" if limited to 250 columns otherwise contains
"nolimit" if unlimited (used when calling readVarsESO)
%convESO% or %8 contains Y if convertESOMTR program should be called
%procCSV% or %9 contains Y if csvProc program should be called
%cntActv% or %10 contains the count of other simulations active or about to be
active
%multithrd% or %11 contains N if multithreading should be disabled
All i want is to pass parameters %1, %2, %3, %4 and %5... the rest should not be set...
Can somebody please tell me how this works? I searched the web and tried for hours but i won`t get this.
Thanks and greets!
It looks to me like the author of this batch file allows you to use it in 2 different ways,
Option 1
Just pass the parameters on the command line,
file.bat Param1 Param2 Param3 .....
Option 2
set the variables listed and then call the batch file with the single parameter that is exactly PARAM.
SET epin=Param1
SET epout=Param2
...
file.bat PARAM
what is the problem with ?:
set "epin=%~dpfn1"
set "epout=%~dpfn2"
set "epinext=%~3"
if /I not .%epinext% equ .imf (
if /I not .%epinext% equ .idf (
echo wrong extension
exit /b 1
)
)
set "epwthr=%%~dpfnx4"
set "eptype=%%~5"
use a short batchfile (in fact it is very short: one line) (you could name it "DoFile.bat")
#file.bat %1 %2 %3 %4 %5 Y "250" Y Y 3 N
It takes 5 parameters and starts the wanted batch with the full amount of 11 parameters.
It might be neccessary to adapt it a little bit to the needs of file.bat
(no errorhandling included)

Echo parameters to a log file

I need to add logging to a batch file to know what parameters were passed to it.
So if the batch file is run.bat, I have tried adding the line
ECHO %1 %2 %3 %4 %5 %6 %7 %8 %9 >> run.log
Which just echoes the parameters and the string >> run.log.
I suspect you have an unclosed quote somewhere in your parameter list (e.g. foo.cmd "bar would cause that behaviour). You can likely solve this by putting the redirection in front of the echo (yes, this works):
>> run.log echo %*

Resources