Avatar billede fredand Forsker
20. februar 2008 - 15:06 Der er 10 kommentarer og
1 løsning

How to pass params to a bat-script that contains

Hello!

I need to pass a parameter containing ";" like:
mybat.bat param1 param2 .;lib\myjar1.jar;lib\myjar2.jar

The problem is taht the only value for param3 thats arrives is "."

Best regards
Fredrik
Avatar billede pidgeot Nybegynder
20. februar 2008 - 15:49 #1
Have you tried surrounding the parameter with double quotes (")?
Avatar billede fredand Forsker
20. februar 2008 - 16:05 #2
Hello!
Yes, and to my surprise it still got the value ".", nothing more.
If I removed the ";" then I got the rest, but I had to change the "\" to "/".
I have also tried singel qoutas (')
/Fredrik
Avatar billede bertelbrander Novice
20. februar 2008 - 19:58 #3
I created a bat-file:
@echo off
:start
if [%1]==[] goto :eof
echo %1
shift
goto :start

And used this command:
cmdline.cmd param1 param2 ".;lib\myjar1.jar;lib\myjar2.jar"

"cmdline.cmd" is the name of the bat-file, it prints:
param1
param2
".;lib\myjar1.jar;lib\myjar2.jar"

As I would expect, if I use
echo %~1
It omits the surrounding "'s
Avatar billede fredand Forsker
20. februar 2008 - 21:07 #4
Hello!

I 'll be darned!
I will try that at office first thing tomorrow!
Btw I used a mybat.bat file, not cmd. Prerhaps taht is why.
I'll get back to you!

/Fredrik
Avatar billede bertelbrander Novice
20. februar 2008 - 21:39 #5
I don't think that the extension makes any difference.
Avatar billede pidgeot Nybegynder
20. februar 2008 - 21:57 #6
There's only a difference between .bat and .cmd if they're launched through a shortcut (.bat will use the old command.com, while .cmd will use cmd.exe, meaning it has more capabilities). However, when launched directly, cmd.exe should be used anyway.

Perhaps the problem is that the .bat-file doesn't re-quote the value when it's using it, causing the "target" to not know they're supposed to be there? Or did you check it by actually echoing it out?
Avatar billede fredand Forsker
21. februar 2008 - 08:52 #7
Hello!

I tried your script, bertelbrander. And that one works fine.
I guess I might not have give you guys the complete image of the problem. The bat file is called from a ant script that gets the value from a properties like:

build.properties:
REM CLASSPATH=.;lib\myjar1.jar;lib\myjar2.jar
REM CLASSPATH=\".;lib\myjar1.jar;lib\myjar2.jar\"
CLASSPATH='.;lib\myjar1.jar;lib\myjar2.jar'

build.xml
  <echo message="${CLASSPATH}"/>
 
  <exec executable="cmd">
  <arg line="/c mybat.bat param1 param2 ${CLASSPATH}"/>
  </exec>

mybat.bat
set CLASSPATH=%9
echo %CLASSPATH%

In the ant echo the classtpath is intact.

But in the bat echo the classpath is just "."

So if you guys perhaps have any ideas do not hasitate!

Best regards
Fredrik
Avatar billede fredand Forsker
21. februar 2008 - 12:57 #8
Hello!

I think I solved it with all your help:
(double quotas in build.properties)
CLASSPATH=".;lib\myjar1.jar;lib\myjar2.jar"

(single quotas around variables that qontains double quotas in build.xml)
<arg line="/c mybat.bat param1 param2 '${CLASSPATH}'"/>

(double quotas around param and tilde to omit the surrounding double qoutas as bertelbrender said, in the maybat.bat)
set CLASSPATH="%~9"
echo %CLASSPATH%

Thank you all for your help!!!

Please all of you, give a svar so I can reward you!

Best regards
Fredrik
Avatar billede pidgeot Nybegynder
21. februar 2008 - 13:17 #9
Here you go :)
Avatar billede bertelbrander Novice
21. februar 2008 - 14:48 #10
I have a habit of not collecting points.
Avatar billede fredand Forsker
21. februar 2008 - 15:03 #11
Hello!

Ok bertelbrander I take your word for it.
I hope you belive me when I said that I am most thankful for your help.

Thank you booth very much!

Best regards
Fredrik
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester