Question

void execute_commands(tokenlist *tokens) { tokenlist* current=tokens; pid_t pid; int status; char* argv[100]; for (int i=0;i<100;i++) argv[i]=(char*)...

void execute_commands(tokenlist *tokens) {

tokenlist* current=tokens;

pid_t pid;

int status;

char* argv[100];

for (int i=0;i<100;i++)

argv[i]=(char*) malloc( sizeof(char) *1000);

int args=0;

int inredirect=0;

while (current->next!=nullptr) {

if (current->data[0]=='|')

printf("Pipe not implemented\n");

if (current->data[0]=='|' || current->data[0]==';') {

printf("\n");

//Run last command

if (args) {

char strcd[]="cd";

char strpwd[]="pwd";

if (strcmp(argv[0],strcd)==0) {

if (args==2) {

if (chdir(argv[1])) {

printf("Directory does not exist or is not accessible.\n");

}

} else {

printf("Accepts exactly one argument\n");

}

My question is why when I input the command "cd (pathName)" the working directory still does not change. What am I missing from the code.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The code is perfectly fine.The problem is that you are using the wrong command for changing the directory.

Actually it is cd/pathName not like cd(pathname).

Following is the complete procedure to change the directory(I will state it through an example):-

The first command from the list is CD (Change Directory). This command enables you to change the current directory or, in other words, to navigate to another folder from your PC. For instance, the command CD\ takes you to the top of the directory tree. To see how it works, after you open the Command Prompt, type cd\ and press Enter on your keyboard. You should see how the CD\ command takes you to the top of the directory tree. In this case, to the "C:" drive.

Note that the Command Prompt is not case sensitive, meaning that you can type commands using capital letters, lowercase or any combination of them. The commands CD, cd or Cd, all work the same way.

Going back to the "CD\" command, now you are working on the root of the "C:" drive. If you need to go to a specific folder from this drive run the command "CD Folder." The subfolders must be separated by a backslash character: "\." For instance, when you need to access the System32 folder located in "C:\Windows," type "cd windows\system32\" as shown below, and then press Enter on your keyboard.

When you need to go one folder up, use the "cd.." command. Let's assume that you want to go back to the Windows folder. Type "cd.." and press Enter on your keyboard.

The effect is that your current directory changes to "C:\Windows."

Add a comment
Know the answer?
Add Answer to:
void execute_commands(tokenlist *tokens) { tokenlist* current=tokens; pid_t pid; int status; char* argv[100]; for (int i=0;i<100;i++) argv[i]=(char*)...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT