Review your favorite Linux distribution.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 09-02-2003, 11:40 PM   #1
Registered: May 2001
Posts: 61

Rep: Reputation: 15
Using execve() not working

I want to modify a program, but I'm have a hard time trying to get the execve() to run any programs. Here is my code:

using namespace std;

void startProgram(const char* binary, char *const file_path[]);

int main()

char fileName[40];
char* const file_path[]={"/usr/bin/"};

cout<<"Starting a program\n\n";
cout<<"Enter the name of the file: ";

return 0;

void startProgram(const char* binary, char *const file_path[])

if(execve(binary,file_path,NULL) == -1)
perror("Error opening program");


Old 09-03-2003, 01:29 AM   #2
Registered: Aug 2003
Location: 63123
Distribution: OpenSuSE/Ubuntu
Posts: 419

Rep: Reputation: 35
I may post a better explaination later, but for now the quick answer is that you are using execve incorrectly. You are using execve like this:

execve(program_name, path_to_program, NULL);

But in fact, execve is defined as this...

execve(program_path, program_argument_list, environment_arg_list);

execve needs you to supply it with a basic set of enviroment variables, so NULL wont cut it. So when you use execve in your program, it craps itself...which is what it should do in that case. If all you want to do is run a program at a certain location try a different exec function that doesnt require a list of environment variables?
Old 09-03-2003, 01:57 AM   #3
Registered: May 2001
Posts: 61

Original Poster
Rep: Reputation: 15
Thanks for the feed back, now I can beat my brains some more.
Old 09-03-2003, 06:26 AM   #4
Senior Member
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 51
execve is quite a beast, i think what your after is one of its wrappers like execl or execlp


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
assembly execve (syscall 11) rblampain Programming 2 07-03-2005 09:23 AM
very urgent!details about execve()??????? vrdhananjay Programming 11 02-08-2005 05:07 PM
Linux syscall 11 (execve) Genjix Programming 1 12-29-2004 11:38 PM
Keeping a lock across execve()? LogicG8 Programming 10 10-30-2003 12:19 PM
fork() and execve() Alf829 Programming 3 08-02-2003 10:18 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:49 PM.

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