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 ??
andersleeAsked:
Who is Participating?
 
rbrConnect With a Mentor Commented:
You can set an enviroment variable set TEXT=Hello World. This varibale can be used in the batch file.
echo %TEXT

0
 
kellyjjCommented:
Why would you want to pass it all as one parameter??
0
 
nils pipenbrinckCommented:
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.


0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
hgnutzmannCommented:
Code:

  Uses DOS;
  Begin
    {$M 8192,0,0}
    Exec(GetEnv('ComSpec'),'/C mybatch.bat HELLO ALL!');
  End.
0
 
andersleeAuthor 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 "

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

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

Is_this_sentence_looks_good_to_you_at_all??
0
 
rbrCommented:
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 ".
0
 
FuzzyLogicCommented:
Anderslee - Do you pass the "Hello world" as plain text argument?
0
 
andersleeAuthor 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.

0
 
FuzzyLogicCommented:
I think I have partial solution.
0
 
Johann091297Commented:
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!');
0
 
FuzzyLogicCommented:
That was also my solution...
0
 
eviltekkCommented:
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%


 
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.