LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 09-03-2003, 12:40 AM   #1
cxel91a
Member
 
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:

#include<string.h>
#include<iostream>
using namespace std;
#include<unistd.h>
#include<errno.h>

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: ";
cin.getline(fileName,40);
startProgram(fileName,file_path);

cout<<endl;
return 0;
}


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


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

cout<<binary<<endl;
cout<<*file_path<<endl;



}
 
Old 09-03-2003, 02:29 AM   #2
jinksys
Member
 
Registered: Aug 2003
Location: 63123
Distribution: OpenSuSE/Ubuntu
Posts: 418

Rep: Reputation: 31
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, 02:57 AM   #3
cxel91a
Member
 
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, 07:26 AM   #4
kev82
Senior Member
 
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

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


Reply


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 10:23 AM
very urgent!details about execve()??????? vrdhananjay Programming 11 02-08-2005 06:07 PM
Linux syscall 11 (execve) Genjix Programming 1 12-30-2004 12:38 AM
Keeping a lock across execve()? LogicG8 Programming 10 10-30-2003 01:19 PM
fork() and execve() Alf829 Programming 3 08-02-2003 11:18 AM


All times are GMT -5. The time now is 04:15 PM.

Main Menu
Advertisement
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