c - Unable to use "execve()" successfully -


The purpose of this program is to create a new hair process and execute a process that has command line logic too. If I enter / bin / ls --help , then I get an error:

  Shadyavi @ Shidababy-Desktop: ~ / lab / 200801076_lab3 $. /a.out Executable (with full path) / bin / ls --help start executable as a new hair process ... binary file executing: / bin / ls / bin / ls: unrecognized Option '--help' try / bin / ls --help 'for more information.     / B> P> 
  contains # lt; Stdio.h & gt; #to & lt include, string.h & gt; // strcpy () #includes & lt; Malloc.h & gt; // Molok () #includes & lt; Unistd.h & gt; // Use of fork () is included & lt; Stdlib.h & gt; Use the // exit () function to include & lt; Sys / wait.h & gt; // test speed () int main (int argc, char ** argv) used {char command [256]; Char ** args = NULL; Char * arg; Int count = 0; Char * binary; Pid_t pid; Printf ("Enter the name of executable (with full path)"); Fgets (command, 256, stdin); Binary = strotok (command, ""); Arg = malloc (sizeof (four *) * 10); Args [0] = malloc (strlen (binary) +1); Strcpy (args [0], binary); Args = realloc (args, sizeof (char *) * 10); count ++ args [count] = (if (= arg = strtok (NULL, "") = =) (if calculation% 10 == 0) Malloc (strlen (arg)); strcpy (args [count], arg);} arg = [calculate] = null; if ((pid = fork ()) == -1) {perror ("fault error. ... ... \ n "); Exit (1);} If (pid == 0) {printf (" Starting executable as a new hair process ... \ n "); Printf ("Binary file to execute:% s \ n", binary); execve (args [0], arg, zero);} Else {int position; waiting speed (-1, and position, 0); printf ("hair Back to process Return:% d \ n ", WEXITSTATUS (status));} return 0;}  

< P> The first entry in the Args array should be the name of the program again. Your code will be the code code / bin / ls with - help as the process name


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -