delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2005/01/21/11:45:24

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
From: Martin Ambuhl <mambuhl AT earthlink DOT net>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: ls.exe in execv
Date: Fri, 21 Jan 2005 11:39:11 -0500
Lines: 61
Message-ID: <35cphlF4jfqigU1@individual.net>
References: <Id3Id.13792$5R DOT 2943 AT newssvr21 DOT news DOT prodigy DOT com>
Mime-Version: 1.0
X-Trace: individual.net kd3OvSgYJgrhZEUvk3JcqALYPYfu8JyQ1xm4Ign11vjqlT1rKu
User-Agent: Mozilla Thunderbird 0.9 (Windows/20041103)
X-Accept-Language: en-us, en
In-Reply-To: <Id3Id.13792$5R.2943@newssvr21.news.prodigy.com>
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

one2001boy AT yahoo DOT com wrote:
> Hello,
> 
> In windows,
> 
> does anybody know if there is a solution for not hanging when run 
> execv()? it seems that running notepad.exe is fine, however, running 
> "ls.exe" compiled with djgpp will hangup the application. Here is the 
> the sample code.
> 
> #include <windows.h>

Why is this posted in news:comp.os.msdos.djgpp?

A corrected version of your code works fine:
#include <stdio.h>
#include <unistd.h>             /* needed for execv */
#include <stdlib.h>             /* needed for exit */
int main(void)
{
     int retval;
     char *argv[] = { "C:/djgpp/bin/ls.exe", "C:/", NULL };
     retval = execv("C:/djgpp/bin/ls.exe", argv);
     printf("if successful, this should not be printed out\n");
     if (retval == -1) {
         fprintf(stderr, "ERROR: 'exec' failed\n");
         perror("exec");
         exit(EXIT_FAILURE); /* fixed */
     }
     exit(0);
}




> #include <stdio.h>
> int main() {
>     char ** environ=_environ;/**** SYSTEM DEFINED ENVIRONMENT POINTER */
>     int retval;
> 
>     /* this is OK
>     char *argv[] = {"C:\\WINDOWS\\SYSTEM32\\notepad.exe", NULL};
>     retval = execv("C:\\WINDOWS\\SYSTEM32\\notepad.exe",  argv);
>     */
> 
>     /*  this will hang
>     */
>     char *argv[] = {"C:\\bin\\ls.exe", "C:\\", NULL};
>     retval = execv("C:\\bin\\ls.exe",  argv);
> 
>     printf("if successful, this should not be printed out\n");
>     if(retval == -1) {
>         fprintf(stderr, "ERROR: 'exec' failed\n");
>         perror("exec");
>         exit(-1);
>     }
>     exit(0);
> }
> 
> 
> thanks.

- Raw text -


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