We help IT Professionals succeed at work.

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

anderslee
anderslee asked
on
Medium Priority
256 Views
Last Modified: 2010-04-16
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 ??
Comment
Watch Question

Commented:
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.

Author

Commented:
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 "

rbr

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

Author

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

Is_this_sentence_looks_good_to_you_at_all??
rbr

Commented:
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?

Author

Commented:
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.

Commented:
You can set an enviroment variable set TEXT=Hello World. This varibale can be used in the batch file.
echo %TEXT

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
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...

Commented:
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%


 
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.