"system()" vs "system_exec()" problem
- Posted by jjnick at cvn.com Apr 29, 2001
- 495 views
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> <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> <BR>Test it out yourself with the = following=20 code:<BR> <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> <BR>constant=20 Win &nbs= p; =20 =3D create( Window, "System=20 calls", 0, Default, Default, = 170, 150,=20 0 ),<BR> <BR> =20 SystemExecButton =3D create( PushButton, "Use system_exec()",=20 Win, 10, 10, = 140, 40, 0 ),<BR> =20 SystemButton =3D create( PushButton, "Use=20 system()", = Win, =20 10, 60, 140, 40, 0 = )<BR> <BR>sequence=20 OScommand<BR>OScommand =3D "testargs \"1 1\" \"2 = 2\""<BR> <BR>global=20 procedure onClick_SystemExecButton()<BR> object = result<BR> result =3D=20 system_exec(OScommand, 0)<BR> 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 &nbs= p;  = ; = =20 <BR> <BR>global procedure onClick_SystemButton()<BR> object=20 result<BR> <BR> system (OScommand, 0)<BR> 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> "Test arguments", MB_ICONINFORMATION+MB_TASKMODAL = )<BR>end=20 procedure &nbs= p;  = ; = =20 <BR> <BR>onClick[SystemExecButton] =3D routine_id( = "onClick_SystemExecButton"=20 )<BR>onClick[SystemButton] =3D routine_id(=20 "onClick_SystemButton" )<BR> <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> <BR>#include = <stdio.h><BR>#include=20 <stdlib.h><BR> <BR>int main( int argc, char *argv[] )=20 {<BR> <BR> if ( argc =3D=3D 3 ) // argc is always at least=20 "1"<BR> printf("\nFound 2 arguments . . = .\n");<BR> =20 getchar();<BR> return( 0 );<BR>}</FONT></FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </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--