delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/03/30/21:27:55

Message-Id: <3.0.5.32.19980330212522.007efe20@pop.iquest.net>
Date: Mon, 30 Mar 1998 21:25:22 -0500
To: "John M. Aldrich" <fighteer AT cs DOT com>, djgpp AT delorie DOT com
From: ricki lee king <rlking AT iquest DOT net>
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

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 <unistd.h>
>> 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 <stdio.h>
>#include <unistd.h>
>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 <stdlib.h>
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


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019