Solved

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

Posted on 1997-09-02
14
234 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 ??
0
Comment
Question by:anderslee
  • 3
  • 3
  • 3
  • +5
14 Comments
 
LVL 2

Expert Comment

by:kellyjj
ID: 1215518
Why would you want to pass it all as one parameter??
0
 
LVL 4

Expert Comment

by:nils pipenbrinck
ID: 1215519
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
 

Expert Comment

by:hgnutzmann
ID: 1215521
Code:

  Uses DOS;
  Begin
    {$M 8192,0,0}
    Exec(GetEnv('ComSpec'),'/C mybatch.bat HELLO ALL!');
  End.
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:anderslee
ID: 1215522
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
 
LVL 10

Expert Comment

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

0
 

Author Comment

by:anderslee
ID: 1215524
If a _ is made for the space,
then I have no problem at all??!!!

Is_this_sentence_looks_good_to_you_at_all??
0
 
LVL 10

Expert Comment

by:rbr
ID: 1215525
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
 
LVL 1

Expert Comment

by:FuzzyLogic
ID: 1215526
Anderslee - Do you pass the "Hello world" as plain text argument?
0
 

Author Comment

by:anderslee
ID: 1215527
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
 
LVL 10

Accepted Solution

by:
rbr earned 100 total points
ID: 1215528
You can set an enviroment variable set TEXT=Hello World. This varibale can be used in the batch file.
echo %TEXT

0
 
LVL 1

Expert Comment

by:FuzzyLogic
ID: 1215520
I think I have partial solution.
0
 

Expert Comment

by:Johann091297
ID: 1215529
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
 
LVL 1

Expert Comment

by:FuzzyLogic
ID: 1215530
That was also my solution...
0
 
LVL 1

Expert Comment

by:eviltekk
ID: 1215531
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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Starting your own business is always a daunting process, and for most people it is brand new experience. Avoid the common pitfalls by following these tips to start on the road to success.
ConnectWise and their customers need to ensure critical alerts automatically reach the right person at the right time. MSP superheros efficiently respond to these alerts key is providing automatic, intelligent alerting that generates a complete audi…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question