Link to home
Start Free TrialLog in
Avatar of anderslee
anderslee

asked on

How to call batch with %1="Hello All"

If I call a batch , I can pass parameter as "BATCH Hello All"  But DOS will treat %1='hello' and %2='all'

How do I force it to take 'hello all' for %1 ??
Avatar of kellyjj
kellyjj

Why would you want to pass it all as one parameter??
That's easy.

you can pass "hello all" as a parameter and the command shell will remove the " and don't split the two words.


Code:

  Uses DOS;
  Begin
    {$M 8192,0,0}
    Exec(GetEnv('ComSpec'),'/C mybatch.bat HELLO ALL!');
  End.
Avatar of anderslee

ASKER

Exec(GetEnv('ComSpec'),'/C mybatch.bat HELLO ALL!');

(1) your code should read:
     Exec(GetEnv('ComSpec'),'/C mybatch.bat "HELLO ALL!"');
(2) DOS will treat  "HELLO ALL!" as %1, including "

Space are treated under DOS to sperate each word. So you need another character for this. The _ (underscore) is made for this.

If a _ is made for the space,
then I have no problem at all??!!!

Is_this_sentence_looks_good_to_you_at_all??
The problem is you can't force DOS tho treat Hello World is one word. You must use another character. Or you have to use "HELLO World" with the ".
Anderslee - Do you pass the "Hello world" as plain text argument?
There may not be a method through command line, but there's
gotta be a way.
At least I encounter one program that can do that.

ASKER CERTIFIED SOLUTION
Avatar of rbr
rbr

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I think I have partial solution.
charcter 255 looks exactly like a space and is not seperated when u send it as a parameter !

so instead of sending the parameter as
  'Hello'+chr(32)+'All!'    {where chr(32) is space}
send
  'Hello'+chr(255)+'All!'   {where chr(255) looks like space
                             but not splitted like space}

now, this should work
  Exec(GetEnv('ComSpec'),'/C mybatch.bat HELLO'+chr(255)+'ALL!');
That was also my solution...
set temp=
:start
if e%1==e goto doneshift
set temp=%temp% %1
shift
goto start
if e%1==e goto doneshift

:doneshift


rem your batch...your data is in the %temp%, or you call the rem batch again with that way: 1.Bat %temp%