hello!
I'm writing a C++ program and I use fork() and execl to call a bash script.My .cpp communicates with the script with a pipe in which the script writes data and then the .cpp reads them.I don't think my script is ever executed the way I'm doing it...
Code:
int pid;
int res = mkfifo (pipeName, 0666);
if (res < 0) {
perror("Error creating the named pipe");
exit (2);
}
pid=fork();
if(pid<0)
{
cerr << "Failed to fork" << endl;
exit(1);
}
if(pid==0){
execl("./bbb","bbb",argv[1],pipeName,NULL);
exit(0);
}
where pipeName is the name of the pipe .cpp and bash script communicate with,argv[1] is just a string,bbb is the name of the script
In my script when I want to write something to the pipe I do
where $2 is the name of the pipe the script got when called.
When I run it it seems to meet a deadlock so I figured maybe the script is never called...
Any ideas?