Trouble using execl

Hi, I'm trying to teach myself a little bit about system calls by making a simple shell.
I've made a copy function and I'm trying to call it with my shell but I keep getting a 'No such file or directory' error. I'm not really sure if it's the function, the files or both that can't be found.

I've tried a bunch of different ways. In the version I'm including here I've provided the path to the files as well as the copy function.

All the files are in the same directory.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include "string.h"

int SIZE = 10;

int main(int argc, char* argv[])
{
  while(1)
  {
    char command[SIZE];
    char arg1[SIZE];
    char arg2[SIZE];  
    int s;
    pid_t  pid;
    int  status;
    char path1[] = "/gary/Documents/myShell/";
    char path2[] = "/gary/Documents/myShell/";
    
    printf("$ ");
    scanf("%s %s %s", command, arg1, arg2);
    strcat(path1, arg1);
    strcat(path2, arg2);
       
    if(fork() !=0 )
    {
       while (wait(&status) != pid)
       ;
    }
    else
    {
      s = execl("/gary/Documents/myShell", command, path1, path2, (char*)0);
      if(s == -1)
	printf("Error: %s\n", strerror(errno));
    }    

  }
    
}
    

Any help would be appreciated.

Thanks,
-gr
Try

execl( "/gary/Documents/myShell", "/gary/Documents/myShell", command,
path1, path2, 0 );

Usually the first "parameter" to an executable is the name of the executable
itself.
Thanks for reply. It's still not working but, since this is just an exercise for myself, I'm moving on.

I appreciate your time.

Thanks,
-gr
Mmm, also you have a memory stomp.

You cannot strcat() anything to path1 or path2 since they are fixed-length strings.
Topic archived. No new replies allowed.