Message-Id: <3.0.5.32.19980330212522.007efe20@pop.iquest.net> Date: Mon, 30 Mar 1998 21:25:22 -0500 To: "John M. Aldrich" , djgpp AT delorie DOT com From: ricki lee king Subject: Re: exec command In-Reply-To: <35203554.718E@cs.com> References: <3 DOT 0 DOT 5 DOT 32 DOT 19980330155332 DOT 00828590 AT pop DOT iquest DOT net> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Precedence: bulk At 07:14 PM 3/30/98 -0500, John M. Aldrich wrote: >ricki lee king wrote: >> >> this runs ping.exe but feeds it garbage for an arguement. >> pls tell me how to fix it. >> >> #include >> main() >> { >> execl("c:/windows/ping","www.iquest.net"); >> } >> >> thanks > >You're using execl() incorrectly. According to the libc docs, it's >prototyped as follows: > > int execl(const char *path, const char *argv0, ...); > >If you use this syntax, then you're making two mistakes: > >1) You are passing "www.iquest.net" as argv[0], which is the name of the >program, instead of argv[1], which is the first argument. > >2) You are not terminating the variable-length argument list with a >NULL, so execl() has no idea when to stop sending arguments. > >You are also forgetting that execl() might return unsuccessfully, in >which case you should trap the error and print a suitable message. > >Correct code: > >#include >#include >int main( void ) >{ > if ( execl( "c:/windows/ping", "c:/windows/ping", "www.iquest.net", >0 ) != 0 ) > perror( "c:/windows/ping" ); > return 1; >} > >I have compiled this code and it works correctly on my system. > >BTW, the following works just as well: > > system( "c:/windows/ping www.iquest.net" ); here is my final isp pinger. it pings my isp about every 12 minutes on my 486. i was daunted by all the time functions so i used a for loop to kill time. i know its ugly. this is my first practical program but i am sure it already exists. i will learn time functions later. #include main() { long double n; system("c:/windows/ping www.iquest.net"); beginsh: for (n=1; n<999999999.01;n++) { } system("c:/windows/ping www.iquest.net"); goto beginsh; } bye