Mail Archives: djgpp/2005/01/23/22:46:26
Martin Ambuhl wrote:
> 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?
I know windows.h is not part of djgpp. I thought the problem is related
to "ls.exe" generated in djgpp. It might be wrong.
Thanks for you and all people's help. I will further look into the problem.
>
> 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 -