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 ??
How do I force it to take 'hello all' for %1 ??
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.
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.
Uses DOS;
Begin
{$M 8192,0,0}
Exec(GetEnv('ComSpec'),'/C
End.
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 "
(1) your code should read:
Exec(GetEnv('ComSpec'),'/C
(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.
ASKER
If a _ is made for the space,
then I have no problem at all??!!!
Is_this_sentence_looks_goo d_to_you_a t_all??
then I have no problem at all??!!!
Is_this_sentence_looks_goo
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?
ASKER
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.
gotta be a way.
At least I encounter one program that can do that.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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!');
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
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%
: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%