I have a file hello.exe
file path is D:\test\hello.exe
which is a simple hello world program (tested ok).
I have another program proc.c
file path is D:\test\proc.c
with code as follows:
#include<stdio.h>
#include<stdlib.h>
#include<windows.h>
#include<process.h>
#include<errno.h>
#include<string.h>
main(int argc,char *argv[])
{
int ret;
ret=execl("D:\\test\\hello.exe","D:\\test\\hello.exe");
if(ret==-1)
printf("%d:\t%s",ret,errno);
}
The program hangs (windows dialog says The program has stopped working
)!!!
I even tried D:/test/hello.exe
as param to execl()
, but the same...
Where am I going wrong??? Please someone provide me the right syntax? Please prvide me example codes using various functions of process.h with MinGW under windows. Web tutorial links are acceptable as well.
Thanks a lt !!!
You have to include a library,
#include<unistd.h>
Because it is defined in this library So if you don't include this you will get AN error. and correct your code because you have written "exec" not execl.
int main()
{
execl("D:/test/hello","D:/test/hello",0);
return 0;
}