Hello,
I'm trying to do the following:
1. parent application is a simple QT app.
2. from the QT app, I fork a child
3. In the child, I call execve("mplayer", "/home/TTux/test.mpg", 0);
But the call to execve() fails. I can't figure out why.
Below is the code snippet:
void mparent:
pen_file()
{
char *args[1];
int launch_error;
QString s = QFileDialog::getOpenFileName("~",
"All Files (*.*)",
this,
"open file dialog",
"Open a file to play"
);
// save the child's pid in parent's context
this->mplayer = fork();
if(this->mplayer)
{
// in parent process
fprintf(stdout, "Child started successfully");
}
else
{
// in child process
args[0] = (char*) s.ascii();
launch_error = execve("mplayer", args, 0);
fprintf(stdout, "mplayer launch failed: error code %d\n", launch_error);
perror("error is");
}
}
The output is:
mplayer launch failed: error code -1
error is: No such file or directory
Xlib: unexpected async reply (sequence 0x30c)!
After this the parent's QT window (QMainWindow instance) does remain there, but after a few moment the whole programme hangs and then crashes. I don't know what's wrong with this code, and why is the Xlib printing out a message. The message "Child started successfully" never gets printed.
Please help.
Thanks!
Kapil