LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 07-22-2006, 01:02 AM   #1
TTux
LQ Newbie
 
Registered: Jun 2004
Location: India, Pune
Distribution: SuSE 10.1
Posts: 8

Rep: Reputation: 0
Exclamation execve fails with "No such file or directory"


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
 
Old 07-22-2006, 01:27 AM   #2
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,502

Rep: Reputation: 357Reputation: 357Reputation: 357Reputation: 357
The arguments you pass to execve are wrong, no surprise it fails.

The first one should be the path to the command, you just give the name, which trigger the "no such file or directory".

The next argument should be an array of arguments, you only give one, and not the first that should be passed (arg[0]).

Try instead:

Code:
execl("/usr/bin/mplayer", "mplayer", "/home/TTux/test.mpg", 0);
 
Old 07-22-2006, 02:17 AM   #3
TTux
LQ Newbie
 
Registered: Jun 2004
Location: India, Pune
Distribution: SuSE 10.1
Posts: 8

Original Poster
Rep: Reputation: 0
Smile Solved!

Hey thanks a lot!
Now my problem is solved. Here's what I have done:

{
char *args;
int launch_error;
QString s = QFileDialog::getOpenFileName("~",
"All Files (*.*)",
this,
"open file dialog",
"Open a file to play"
);

this->mplayer = fork();

// in parent process
if(this->mplayer)
{
fprintf(stdout, "Child started successfully\n");
}

// in child process
else
{
args = (char*) s.ascii();
launch_error = execlp("mplayer",
"mplayer",
args,
(char*)NULL);
fprintf(stdout, "mplayer launch failed: error code %d\n", launch_error);
perror("error is");
}
}

This works well :-)

Thanks again!
 
  


Reply

Tags
qt


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"bad interpreter : no such file or directory" when configure "flex" acer_peri Linux - Software 10 11-10-2010 01:19 AM
SimpleScalar: sslittle-na-sstrix/bin/ld: crt0.o: "no such file or directory" lydia.plath Linux - Software 0 03-18-2006 12:55 PM
Useful article: "Linux File & Directory Permission Mistakes" sundialsvcs Linux - Security 1 08-15-2005 11:50 AM
error while trying to install program: "X11/Xlib.h: No such file or directory" nate1 Linux - Newbie 3 05-21-2004 08:08 AM
Debian kernels: "warning: can't open /etc/mtab: No such file or directory" brurien Debian 1 10-22-2003 06:09 PM


All times are GMT -5. The time now is 11:12 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration