1

It seems like it would be simple. In a bat file, I call a program that takes command line parameters I have the parms as one string, I have tried it with "" around and not It only sees one parm (if guess it hit the space)

So the question is how can I pass the string, as a parameter list The actual string is below and must be formated as such with the "" etc

-U romeirj -P Abc123 -F C:\inetpub\wwwroot\russ\crexport\russ.rpt -O C:\inetpub\wwwroot\russ\russ.pdf -A "startdate: 01-01-2010" -A "gender:M" -A "type:PENDJUD"

would like to call it from a bat file the looks like

batfile.bat parmstring

bat file content

program.exe %1
1
  • Spoke to soon the problem now is with the calling pgm looking to call with wsh from asp as below, tried it with & chr(34) on each end of parmstr etcparmstr = sReportName & sOutputName & sUserID & sPW & sParm1 & sParm2 & sParm3 wshell = CreateObject("WScript.Shell") wshell.exec ("c:\run_russ_rpt_parm.bat" & Parmstr) wshell = nothing
    – Russ Romei
    Commented Jun 7, 2012 at 15:30

1 Answer 1

3

As long as all of the batch parameters are supposed to be passed to your program, then you can simply call your batch with the parameters as you have specified them, and use the following within your batch script.

program.exe %*

The problem becomes much more complicated if you only want to pass some of the batch parameters to the called program.

Unfortunately there is no method to escape quotes within a quoted string. It is also impossible to escape parameter delimiters. So it is impossible to simultaneously embed both spaces and quotes within a single batch parameter.

The SHIFT command can strip off leading parameters, but %* always expands to the original parameter list; it ignores prior SHIFT operations.

The FOR /F does not ignore quoted delimiters, so it doesn't help.

The simple FOR can properly parse quoted parameter lists, but it expands * and ? characters using the file system. That can be a problem.

The only thing left to do is to use a GOTO loop combined with SHIFT to build a string containing your desired parameters.

Suppose the first 3 parameters are strictly for the batch file, and the remaining parameters are to be passed to the called program.

@echo off
setlocal

set "args="
:buildProgramArgs
if [%4]==[] goto :argsComplete
set args=%args% %4
shift /4
goto :buildProgramArgs

:argsComplete
program.exe %args%

::args %1 %2 and %3 are still available for batch use
4
  • @RussRomei - Don't forget to accept the answer if it meets your needs. (click the check mark). That action lets people know the question has been answered, it awards you the questioner 2 points, and awards the answerer 15 points.
    – dbenham
    Commented Jun 7, 2012 at 15:07
  • Spoke to soon the problem now is with the calling pgm looking to call with wsh from asp as below, tried it with & chr(34) on each end of parmstr etc parmstr = sReportName & sOutputName & sUserID & sPW & sParm1 & sParm2 & sParm3 wshell = CreateObject("WScript.Shell") wshell.exec ("c:\run_russ_rpt_parm.bat" & Parmstr) wshell = nothing
    – Russ Romei
    Commented Jun 7, 2012 at 15:37
  • @RussRomei: Your parmstr seems to be missing spaces in-between the various items it is being made of. A space is also needed between the bat file name and parmstr.
    – Andriy M
    Commented Jun 7, 2012 at 15:46
  • @RussRomei - I don't fully understand your latest need, but it sounds like it should be a new question. Or at least clearly edit your original question with the new requirement.
    – dbenham
    Commented Jun 7, 2012 at 16:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.