Commit 88ca72b2 authored by Zara Saldanha's avatar Zara Saldanha

Delete ishell2.c

parent f3f54ddd
#include <stdio.h>
#include <stdlib.h>
#include "wrappers.h"
#include <sys/types.h>
#include <string.h>
#include <libgen.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define BUFFER 1500
int main(){
char input[BUFFER];
char* argv[150];
char* path= "/bin/";
char shell_path[30];
int status;
int i;
char *input_split;
while(1){
printf("ishell> ");
if(!fgets(input, BUFFER, stdin)){
break;
}
if(strcmp(input, "exit\n")==0){
break;
}
size_t length = strlen(input);
if (input[length - 1] == '\n'){
input[length - 1] = '\0';
}
input_split = strtok(input," ");
int count=0;
while(input_split!=NULL){
argv[count]=input_split;
input_split = strtok(NULL," ");
count++;
}
argv[count]=NULL;
for(i=0; i<count; i++){
printf("%s\n", argv[i]);
}
strcpy(shell_path, path);
strcat(shell_path, argv[0]);
for(i=0; i<strlen(shell_path); i++){
if(shell_path[i]=='\n'){
shell_path[i]='\0';
}
}
int pid= Fork();
if(pid==0){
//child process
execvp(shell_path,argv);
}else{
//parent process
Wait(&status);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment