473,385 Members | 1,661 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Problems whith 'execve' args...

I need to implement a prompt of commands (mere academic project). The
function presents errors in the call execve, as parameter. It follows
the code below. I´m using gcc... thanks.

#include "stdio.h"
#include "unistd.h"
#include "sys/types.h"


void type_prompt(); //shows the prompt
void parser(char linha[] , char command[] , char **params ); // it
separates the command of the parameters
void read_command( char command[] , char params[][] ); // read the
command line


#define COMANDOSPERMITIDOS 9 //amount of command args
#define TAMMAX 100 //length of string allowed


int main (void) {
char command[TAMMAX] , params[COMANDOSPERMITIDOS][TAMMAX];
int pid , status;
while(1){
type_prompt();
read_command(command,params);
pid = fork();

if (pid < 0 ){
printf("Unable to fork");
continue;
}

if(pid != 0) {
waitpid(-1,&status,0);
}else {
execve(command , (char*)params ,0); // the error
appears here
}
}
getch();
exit(0);
return 0 ;
}


void type_prompt(){
printf("\n$ ");
}

void read_command( char command[] , char params[][] ){
char linha[TAMMAX];
gets(linha); //reading the command line from user
parser( linha , command , params );
}

void parser( char linha[] , char command[] , char **params ){
int i = 0 ;
int j = 0 ;
int k = 0 ;
for ( i = 0 ; i < TAMMAX ; i++ ){
if( linha[i] != '\0' ){
if ( linha[i] != ' ' ){ // isolating the command
command[i] = linha[i];
}else{
command[i] = '\0';
break;
}
} else break;
}


j = 0 ;
k = 0;
i = 0 ;

for( j = 0 ; j < TAMMAX ; j++ ){

if( linha[j] != '\0' ){ //repetir até o fim da string
if( linha[j] != ' ' ){ // isolating the params
params[i][k] = linha[j];
k++;
}
else{
params[i][k] = '\0';
k = 0 ;
i++;
}
} else{
params[i][k] = '\0';
k = 0 ;
i++;
break;
}
}

while (i < COMANDOSPERMITIDOS){
params[i][0] = '\0';
i++;
}
}
Oct 17 '06 #1
0 2548

Sign in to post your reply or Sign up for a free account.

Similar topics

20
by: Lucas Raab | last post by:
I'm done porting the C code, but now when running the script I continually run into problems with lists. I tried appending and extending the lists, but with no avail. Any help is much appreciated...
3
by: Java Boy | last post by:
HI there... I compile the following code(as root) and sets the setuid bit... as it gives a shell to any user but when the setuid bit is set the shell should have the privileges of root but in my...
2
by: James Colannino | last post by:
Hey everyone. I'm writing a small application in Python that uses os.fork() to create a separate process in which another application is run in the background. The problem is that I need to know...
2
by: goodnamesalltaken | last post by:
Hello fellow python users, I've been working on a basic implementation of a privilege separated web server, and I've goto the point of running a basic cgi script. Basically when the execCGI...
2
by: J4CK4L | last post by:
Hi everyone, I've just created a function in a header file that accept a string and parse but the prototipe of the function return me an exception: #include <stdio.h> #include <string.h> int...
4
by: neojia | last post by:
hi, I am trying to figure out the system call from user space to kernel space. So, I read glibc wrapper first. But I cannot figure out the exact meaning of INTERNAL_SYSCALL for execve system...
1
by: kevin.a.sweeney | last post by:
I would like to open an application from a hyperlink on a webpage. 1. the webpage is located on my local machine. 2. the application is located on my local machine. 3. the application will run...
2
by: scoobydoo666 | last post by:
Hi I want to execute a command using execve() from my program. Is it possible to get the output redirected to a buffer/file like popen() does? Thanks
2
by: Epetruk | last post by:
Hello, I have an ASP.NET page which consists of a button (cmdSave), a label (lblMessage), a text field (txtName) and a custom validator (vldName). vldName is supposed to do both client *and*...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.