Skip to content

Commit

Permalink
Added ampersand for piping
Browse files Browse the repository at this point in the history
  • Loading branch information
Biscuitmunch committed Mar 29, 2022
1 parent 2067094 commit fc89c83
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions ash.c
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ void executeWithPipes(char ***userArgs, int amper, int pipeNum, char *constantFu

}

char ***createPipeArgInput(char **userArgs, int amper, char *constantFullCommand)
char ***createPipeArgInput(char **userArgs, int amper, char *constantFullCommand, char **jobCommandsAmper, pid_t *jobIDs)
{
int buffsize1 = 10;
int buffsize2 = 10;
Expand Down Expand Up @@ -420,6 +420,31 @@ char ***createPipeArgInput(char **userArgs, int amper, char *constantFullCommand
int errorMsg;
waitpid(runningPipeCommand, &errorMsg, 0);
}
else
{
if (jobsRunning == 0)
{
processCounter = 1;
jobsRunning++;
jobCommandsAmper[processCounter] = strdup(constantFullCommand);
jobIDs[processCounter] = runningPipeCommand;
printf("[%d] %d\n", processCounter, runningPipeCommand);
}
else
{
jobsRunning++;
processCounter++;
int countdown = processCounter;
while (jobIDs[countdown] == '\0')
{
countdown--;
}
countdown++;
jobCommandsAmper[countdown] = strdup(constantFullCommand);
jobIDs[countdown] = runningPipeCommand;
printf("[%d] %d\n", processCounter, runningPipeCommand);
}
}
}

}
Expand Down Expand Up @@ -462,7 +487,7 @@ char **historyCommands, char **jobCommandsAmper, pid_t *jobIDs)
{
if (pipeExists == 1)
{
createPipeArgInput(userArgs, amperValue, constantFullCommand);
createPipeArgInput(userArgs, amperValue, constantFullCommand, jobCommandsAmper, jobIDs);
}
else if (amperValue == 1)
{
Expand Down

0 comments on commit fc89c83

Please sign in to comment.