basic shell - ls command after chdir()
NickName:user5944648 Ask DateTime:2016-02-18T16:19:15

basic shell - ls command after chdir()

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?

Copyright Notice:Content Author:「user5944648」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/35476143/basic-shell-ls-command-after-chdir

More about “basic shell - ls command after chdir()” related questions

basic shell - ls command after chdir()

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 comman...

Show Detail

Chdir lagging Shell

I am writing a shell in C/C++. When I try changing the directory with chdir(const char*), the shell starts to lag. The shell works very good until somthing like cd .. is typed. Then when I try typi...

Show Detail

Linux Shell in C : chdir() Behaving Odd

first off, this is an assignment for my Operating Systems class. So, I am writing my own shell in C in Linux. Part of the requirements is to implement the cd command using chdir(). Here is my code

Show Detail

How to write output of a shell command to a socket in c?

I'm trying to implement a basic ftp client-server program. The client should be able to connect to the server and navigate it through commands like cd and ls. I was wondering how could I write the ...

Show Detail

Making a shell in C, but can't get chdir to work?

I'm writing a shell in C that's supposed implement several commands, one of them being the change directory command. To change directories, I use chdir(), but every time I run my code, I get a

Show Detail

C Corrupted double-linked list after calling chdir

I've been working on some C code to provide functionality similar to the shell. So far it can run most commands like cat, ls, ls | grep ..., etc. After writing code to implement the functions "cd",...

Show Detail

C, Fork(), take CL argument and execute CHDIR

#include <stdio.h> #include <stdlib.h> #include <pthread.h> #include <unistd.h> char *getcwd(char *buf, size_t size); //define getcwd char PATH_MAX[1024]; //define max size of

Show Detail

ls -l command for listing specific folder content in adb shell

there is an issue that I want to create a bat file in a way of opening a folder with adb commands in (dev/block/platform/ ) directory that its only one folder with unique name for each device (7824...

Show Detail

How to use inbuild shell command with popen

So, I have to build a custom shell, which can execute all sh commands and all binaries located in /usr/bin and others binairies files included into shell, but I currently cannot use inbuild cd and ...

Show Detail

storing the output of ls command in a shell variable

I am using below command to find a most recent file with name "candump" ls *.log | grep "candump" | tail -n 1 The output is "candump-2018-04-19_131908.log" I want to store the output filename to a

Show Detail