You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Mikael Vidstedt <mi...@stacken.kth.se> on 1999/06/23 10:45:34 UTC
Escaping arguments and ap_call_exec
Hello!
I'm writing a module for apache under windows. The module should start a
program and I use ap_bspawn_child to do that. My function (the second
argument to ap_bspawn_child) calls ap_call_exec. r->filename is set to the
name of the program I want to run, and r->args is a string containing the
argument to that program. Now, the trouble is that my argument string is
escaped when I receive it in the program, and spaces in the original
argument string are treated as argument separators.
E.g:
An argument string sent as:
r->args = ap_pstrcat(r->pool,
r->args,
"d:\\program files\\my_program.exe");
Arrives as:
argv[1] == d:\\program
argv[2] == files\\my_program.exe
If I use slashes I still have trouble with the space.
If I choose to double-quote the string I end up with:
argv[1] == "d:\\program
argv[2] == files\\my_program.exe\"
So, how am I supposed to format that string before sending it to
ap_call_exec?
Thanks,
Mikael
Re: Escaping arguments and ap_call_exec
Posted by Bill Stoddard <st...@raleigh.ibm.com>.
Mikael Vidstedt wrote:
>
> Hello!
>
> I'm writing a module for apache under windows. The module should start a
> program and I use ap_bspawn_child to do that. My function (the second
> argument to ap_bspawn_child) calls ap_call_exec. r->filename is set to the
> name of the program I want to run, and r->args is a string containing the
> argument to that program. Now, the trouble is that my argument string is
> escaped when I receive it in the program, and spaces in the original
> argument string are treated as argument separators.
>
Yep, looks like a bug in ap_call_exec. I'll look at it when I get some
time.
--
Bill Stoddard
stoddard@raleigh.ibm.com
Re: Escaping arguments and ap_call_exec
Posted by Khimenko Victor <ap...@khim.sch57.msk.ru>.
23-Jun-99 10:45 you wrote:
MV> Hello!
MV> I'm writing a module for apache under windows. The module should start a
MV> program and I use ap_bspawn_child to do that. My function (the second
MV> argument to ap_bspawn_child) calls ap_call_exec. r->filename is set to the
MV> name of the program I want to run, and r->args is a string containing the
MV> argument to that program. Now, the trouble is that my argument string is
MV> escaped when I receive it in the program, and spaces in the original
MV> argument string are treated as argument separators.
MV> E.g:
MV> An argument string sent as:
MV> r->args = ap_pstrcat(r->pool,
MV> r->args,
MV> "d:\\program files\\my_program.exe");
MV> Arrives as:
MV> argv[1] == d:\\program
MV> argv[2] == files\\my_program.exe
MV> If I use slashes I still have trouble with the space.
MV> If I choose to double-quote the string I end up with:
MV> argv[1] == "d:\\program
MV> argv[2] == files\\my_program.exe\"
MV> So, how am I supposed to format that string before sending it to
MV> ap_call_exec?
Just like URL but without spaces in arguments :-)) There are error in
ap_call_exec ... If someone if interested in fixing: every argument with
spaces must be surrounded by " under Win32. ap_call_exec does not do
it now (Ok, may be it's fixed in CVS) and will escape " with \ so caller
routine can not fix it as well.
P.S. If argument without spaces will be surrounded by " then most programs
(all programs created with MS VC++ [2-6]) will be fine but it's possible
to find out that redundant " via GetCommandLine() function...