0

I'd like to pass a variable with multiple spaces to a batch script, but it removes multiple spaces and replaces it with one.

C:\user\bat\myscript.bat var1 var2 "'var3'" "'some text followed by double blank__some more text'"

__ are to show the two blanks (' ', spaces, not underscore)

I already tried with %~4, %4 etc. but it always removes the double blanks.

br, Manuel

The bat script is called from a Java application which gets the whole call string from a database.

Script call:

C:\user\bat\eqkvard.bat C:\user\reports\eqkvard.rdf C:\user\output\kontrollvarianten\myoutput.pdf "''" 
"'00.101 D-Bereiche LKZ + OKZ(blank)(blank)L52 Gbd.151 -Mediafill'" 

The site does not show both blanks. The syntax for the quotes is the following: (")(')text(")

Script itself:

START "myprogram" /MIN rwrun report=%1 userid=user/pw@myDB desformat=pdf destype=file desname=%2 p_1=%3 p_2=%4 

The script calls the Oracle reports runtime with the parameters. Hope this can help.

jeb
  • 78,592
  • 17
  • 171
  • 225
Manuel U.
  • 1
  • 1
  • 3
    Enclosing the variable in double-quotes (`"`) is sufficient to pass multiple spaces in (the single-quotes (`'`), unless part of the parameter itself, are not needed). _However_, what you **do** with the variable inside the script can make a difference. Edit the question with an [MCVE] of your script, indicating what you want it to do and what it is doing instead. – TripeHound Jan 31 '17 at 11:02
  • Works perfectly well for me (W10). Perhaps you should show us `myscript.bat` and describe how you are executing the batch. – Magoo Jan 31 '17 at 11:07
  • Thank you for your comments. The bat script is called from a Java application which gets the whole call string from a database. And yes, the single quotes are part of the parameter. Script call: C:\user\bat\eqkvard.bat C:\Aquery\reports\eqkvard.rdf C:\user\output\kontrollvarianten\myoutput.pdf "''" "'00.101 D-Bereiche LKZ + OKZ L52 Gbd.151 -Mediafill'" Script itself: START "myprogram" /MIN rwrun report=%1 userid=user/pw@myDB desformat=pdf destype=file desname=%2 p_matnr=%3 p_kpname=%4 The script call the Oracle reports runtime with the parameters. Hope this can help. – Manuel U. Jan 31 '17 at 11:43
  • Edit the script into the question -- it's impossible to read in a comment. – TripeHound Jan 31 '17 at 12:04
  • @ManuelU.Using a test program in place of `rwrun`, what you have _seems_ to be preserving the blanks (including the double blank); it could be a problem with how `rwrun` handles parameters. You could try replacing `p_1=%3 p_2=%4` with `"p_1=%~3" "p_2=%~4"`. Double-quoting in the call to the batch file should preserve space, but leaves the double-quotes as part of the parameters. Using the tilde (`%~3`) removes the double-quotes, and (re)enclosing the whole `"p_1=...."` in double-quotes may then preserve them for `rwrun` to see. [cont] – TripeHound Jan 31 '17 at 13:37
  • [cont] If that change doesn't work, make sure you can execute `rwrun` directly from a command-prompt (_not_ using `start`) and successfully pass in parameters with (double) spaces in... if you can't do it directly, you be unlikely to be able to from a batch-file. – TripeHound Jan 31 '17 at 13:39

1 Answers1

0

Thank you for your answers. The problem was in the Java call of Runtime exec, which removes double blanks from the String. It may be possible with an String array, but this is not suitable for my case.

If you are having the same problem with the Java exec command, the following post may help.

Runtime Exec with multiple spaces

Community
  • 1
  • 1
Manuel U.
  • 1
  • 1