X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f From: Martin Ambuhl 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: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net kd3OvSgYJgrhZEUvk3JcqALYPYfu8JyQ1xm4Ign11vjqlT1rKu User-Agent: Mozilla Thunderbird 0.9 (Windows/20041103) X-Accept-Language: en-us, en In-Reply-To: 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 Precedence: bulk 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 Why is this posted in news:comp.os.msdos.djgpp? A corrected version of your code works fine: #include #include /* needed for execv */ #include /* 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 > 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.