"system()" vs "system_exec()" problem

new topic     » topic index » view thread      » older message » newer message

This is a multi-part message in MIME format.

------=_NextPart_000_003C_01C0D097.B82140C0
	charset="Windows-1252"

I am pretty sure that the behavior of "system_exec()" is not desired:
=20
- "testargs.exe" will print a confirmation message that it found 2 =
arguments
- Calling "testargs.exe" with "system_exec()" with the following =
arguments: 'testargs "1 1" "2 2"' produces nothing . . .
- Yet, Calling "testargs.exe" with "system()" with the same arguments =
produces the correct result, "2"
=20
Test it out yourself with the following code:
=20
"TESTARGS.EXW"

include win32lib.ew
without warning
=20
constant Win              =3D create( Window,     "System calls",        =
0, Default, Default, 170, 150, 0 ),
=20
         SystemExecButton =3D create( PushButton, "Use system_exec()", =
Win,      10,      10, 140,  40, 0 ),
         SystemButton     =3D create( PushButton, "Use system()",      =
Win,      10,      60, 140,  40, 0 )
=20
sequence OScommand
OScommand =3D "testargs \"1 1\" \"2 2\""
=20
global procedure onClick_SystemExecButton()
 object result
 result =3D system_exec(OScommand, 0)
 result =3D message_box(sprintf( "%s", { "When testargs.exe is passed =
the following: 'testargs \"1 1\" \"2 2\"', nothing happens . . ." } ), =
"Test arguments", MB_ICONINFORMATION+MB_TASKMODAL )
end procedure                                      =20
=20
global procedure onClick_SystemButton()
 object result
=20
 system (OScommand, 0)
 result =3D message_box(sprintf( "%s", { "Yet, when testargs.exe is =
passed the same arguments: 'testargs \"1 1\" \"2 2\"', testargs.exe =
recognizes the 2 arguments" } ),
  "Test arguments", MB_ICONINFORMATION+MB_TASKMODAL )
end procedure                                      =20
=20
onClick[SystemExecButton] =3D routine_id( "onClick_SystemExecButton" )
onClick[SystemButton]     =3D routine_id( "onClick_SystemButton" )
=20
WinMain( Win, Normal )

"TESTARGS.C"
=20
#include <stdio.h>
#include <stdlib.h>
=20
int main( int argc, char *argv[] ) {
=20
  if ( argc =3D=3D 3 ) // argc is always at least "1"
    printf("\nFound 2 arguments . . .\n");
  getchar();
  return( 0 );
}

As all of you know, including double quotes (") on the command line is =
perfectly legal under a DOS box . . .

Obviously, there is something with the way "system_exec()" processes =
double quotes (").

------=_NextPart_000_003C_01C0D097.B82140C0
Content-Type: text/html;
	charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Dwindows-1252">
<META content=3D"MSHTML 5.50.4134.600" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=3DArial size=3D2>I am pretty sure that the behavior of=20
"system_exec()" is not desired:<BR>&nbsp;<BR>- "<FONT=20
face=3D"Courier New">testargs.exe</FONT>" will print a confirmation =
message that=20
it found 2 arguments<BR>- Calling "<FONT face=3D"Courier =
New">testargs.exe</FONT>"=20
with "<FONT face=3D"Courier New">system_exec()</FONT>" with the =
following=20
arguments: <FONT face=3D"Courier New">'testargs "1 1" "2 2"</FONT>' =
produces=20
nothing . . .<BR>- Yet, Calling "<FONT face=3D"Courier =
New">testargs.exe</FONT>"=20
with "<FONT face=3D"Courier New">system()</FONT>" with the same =
arguments produces=20
the correct result, "2"<BR>&nbsp;<BR>Test it out yourself with the =
following=20
code:<BR>&nbsp;<BR>"TESTARGS.EXW"</FONT></DIV><FONT face=3DArial =
size=3D2>
<DIV><BR><FONT face=3D"Courier New" size=3D1>include =
win32lib.ew<BR>without=20
warning<BR>&nbsp;<BR>constant=20
Win&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;=20
=3D create( Window,&nbsp;&nbsp;&nbsp;&nbsp; "System=20
calls",&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0, Default, Default, =
170, 150,=20
0 ),<BR>&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
SystemExecButton =3D create( PushButton, "Use system_exec()",=20
Win,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 10,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 10, =

140,&nbsp; 40, 0 ),<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
SystemButton&nbsp;&nbsp;&nbsp;&nbsp; =3D create( PushButton, "Use=20
system()",&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
Win,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
10,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 60, 140,&nbsp; 40, 0 =
)<BR>&nbsp;<BR>sequence=20
OScommand<BR>OScommand =3D "testargs \"1 1\" \"2 =
2\""<BR>&nbsp;<BR>global=20
procedure onClick_SystemExecButton()<BR>&nbsp;object =
result<BR>&nbsp;result =3D=20
system_exec(OScommand, 0)<BR>&nbsp;result =3D message_box(sprintf( "%s", =
{ "When=20
testargs.exe is passed the following: 'testargs \"1 1\" \"2 2\"', =
nothing=20
happens . . ." } ), "Test arguments", MB_ICONINFORMATION+MB_TASKMODAL =
)<BR>end=20
procedure&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;<BR>global procedure onClick_SystemButton()<BR>&nbsp;object=20
result<BR>&nbsp;<BR>&nbsp;system (OScommand, 0)<BR>&nbsp;result =3D=20
message_box(sprintf( "%s", { "Yet, when testargs.exe is passed the same=20
arguments: 'testargs \"1 1\" \"2 2\"', testargs.exe recognizes the 2 =
arguments"=20
} ),<BR>&nbsp; "Test arguments", MB_ICONINFORMATION+MB_TASKMODAL =
)<BR>end=20
procedure&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;<BR>onClick[SystemExecButton] =3D routine_id( =
"onClick_SystemExecButton"=20
)<BR>onClick[SystemButton]&nbsp;&nbsp;&nbsp;&nbsp; =3D routine_id(=20
"onClick_SystemButton" )<BR>&nbsp;<BR>WinMain( Win, Normal =
)</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D1><BR><FONT face=3DArial=20
size=3D2>"TESTARGS.C"<BR></FONT>&nbsp;<BR>#include =
&lt;stdio.h&gt;<BR>#include=20
&lt;stdlib.h&gt;<BR>&nbsp;<BR>int main( int argc, char *argv[] )=20
{<BR>&nbsp;<BR>&nbsp; if ( argc =3D=3D 3 ) // argc is always at least=20
"1"<BR>&nbsp;&nbsp;&nbsp; printf("\nFound 2 arguments . . =
.\n");<BR>&nbsp;=20
getchar();<BR>&nbsp; return( 0 );<BR>}</FONT></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>As all of you know, including double =
quotes (") on=20
the command line is perfectly legal under a DOS box . . .</DIV>
<DIV><BR>Obviously, there is something with the way "<FONT=20
face=3D"Courier New">system_exec()</FONT>" processes double quotes=20

------=_NextPart_000_003C_01C0D097.B82140C0--

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu