can anyone help me with my code. i am trying to make the exec read input from the keyboard but i have no idea how to start. the code works if the path and the file names are already there..here is what i have done so far with the child process code. the code runs under linux or unix only.

#include <stdio.h>
main()
{
 int PorC, pid, status;
 char path,argum;
 if ((PorC=fork())==0)
 {
  printf ("Enter the path name ");
  scanf ("%c", &path);

  execl ("&path", "&path", "one", 0);
 //originally the code without input from keyboard is commented below and it works well
 // execl ("main_prog","main_prog","one",0);
 //the file main_prog is in the same dir so i use the same file name
  fprintf(stderr, "exec() call failed\n");
  exit(-1);
 }
 else
 {

  printf("this is parent\n");
  pid = wait(&status);
 }
}
char path,argum; /* path needs to be a string or array of chars */

printf ("Enter the path name ");
scanf ("%c", &path); /* It's getting only one character it needs to read a string */

thanx for that...hadnt noticed it....i now need the code to loop. it prompts the user the first time and on the second prompt it doesnt take any input it just waits for a unix command..here is the full code again..

#include <stdio.h>
#include <string.h>
#define LEN 20
main()
{
 int PorC, pid, status;
 char path[LEN+1];
 char argu[LEN+1];
 char resp;
 do
 {
   if ((PorC=fork())==0)
   {
     printf ("Enter the path name: ");
     scanf ("%s",path);
     printf ("Enter the argument: ");
     scanf ("%s",argu);
     execl (path, path, argu, 0);
     fprintf(stderr, "exec() call failed\n");
     exit(-1);
   }
   else
   {
     pid = wait(&status);
   }
 printf("Do you wish to continue? (Y/N): ");
 scanf("%c", &resp);
 }while (resp == 'y');
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.