-1

I'm trying to create a basic shell, but I have a problem. The shell changes directory just fine, and outputs an error if the user inputs an invalid directory. The shell also has an internal command for "pwd" and prints out the new working directory after changing directory. However, if I call the "ls" command after changing the directory, I get the following error :

"ls: cannot access : No such file or directory".

The "cd" command is handled in the parent process and the working directory is changed successfully. execvp() is called in the child process. If I call the "ls" command with the new working directory, the ls command lists out the files just fine, but if I just call "ls" by itself I get the error. What could be the cause of the problem?

1 Answers1

1

The error only indicates nothing passed as an argument to ls command. It is equivalent to running the following.

ls ""

Check or print the command before you calling the ls command in your program.

Umamahesh P
  • 1,224
  • 10
  • 14
  • This answer solved my problem! What was happening was that I didn't do memset on my array of argument tokens and therefore the tokens array had as many tokens as the previous command. – user5944648 Feb 18 '16 at 08:50