pish/src/Pish.c

46 lines
1.3 KiB
C
Raw Normal View History

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
2022-10-22 20:47:03 -05:00
#include <string.h>
#include "Integrated.h"
#include "Pish.h"
// Main function for Pish program
void Pish(void)
{
CommandStruct commandObject = {"", 0};
CommandStruct* command = &commandObject;
char inputString[1000]; // Max 1000 characters
int forkPID;
ReadPishrc(command, inputString);
while (1)
{
ResetCommandStruct(command); // Clean command
strcpy(inputString, ""); // Clean inputString
GetInput(inputString);
2022-10-28 23:00:52 -05:00
// ParseInput(inputString, command);
CheckRedirection(inputString, command);
ioRedirection(command);
if (IntegratedCheck(command))
continue;
forkPID = fork();
2022-10-19 21:14:59 -05:00
// Child
if (forkPID == 0)
{
// This is the child process
// Setup the child's process environment here
// E.g., where is standard I/O, how to handle signals?
// execve() is recommended, execvpe() may be better
execvp(command->argv[0], command->argv);
// exec does not return if it succeeds
printf("ERROR: Could not execute %s\n", inputString);
exit(1);
2022-10-19 21:14:59 -05:00
}
// Parent
// This is the parent process; Wait for the child to finish
wait(&forkPID);
}
}