I’m stuck on Stage #NI6
And when i run it in my console it works but the test won’t go trough.
I’ve tried adding enter characters, checking code on github, changing text to be written.
Here are my logs:
[tester::#PN5] Running tests for Stage #PN5 (The exit builtin)
[tester::#PN5] Running ./your_shell.sh
[your-program] $ invalid_orange_command
[tester::#PN5] Output does not match expected value.
[tester::#PN5] Expected: "invalid_orange_command: command not found"
[tester::#PN5] Received: ""
[tester::#PN5] Assertion failed.
[tester::#PN5] Test failed
When i run it:
❯ ./your_shell.sh
$ invalid_orange_command
invalid_orange_command: command not found
$
And here’s a snippet of my code:
char *getFunctionPath(char *function, char **envPaths) {
if (!function || !envPaths) {
return NULL;
}
static char fullPath[PATH_MAX];
for (int i = 0; i < size; i++) {
snprintf(fullPath, PATH_MAX, "%s/%s", envPaths[i], function);
if (access(fullPath, X_OK) == 0) {
return envPaths[i];
}
}
return NULL;
}
void systemOtherFunction(char *operation, char *params, char **envPaths) {
char *fullPath = getFunctionPath(operation, envPaths);
if (!fullPath) {
fprintf(stderr, "%s: command not found\n", operation);
return;
}
FILE *fp;
char data[PATH_MAX];
char command[PATH_MAX];
snprintf(command, sizeof(command), "PATH=%s %s %s", fullPath, operation,
params ? params : "");
/* printf("%s", command); */
fp = popen(command, "r");
if (fp == NULL) {
printf("Error running a command");
}
while (fgets(data, 1024, fp) != NULL)
printf("%s", data);
pclose(fp);
return;
}
int main(int argc, char *argv[]) {
// Wait for user input
char input[100];
char **envPaths = getEnvPaths();
if (!envPaths) {
fprintf(stderr, "Failed to get EnvPaths! \n");
return EXIT_FAILURE;
}
do {
printf("$ ");
fflush(stdout);
fgets(input, 100, stdin);
input[strcspn(input, "\n")] = 0;
char *reminder;
char *operation = strtok_r(input, " ", &reminder);
// printf("%lu", hash(operation));
switch (hash(operation)) {
case EXIT:
cleanup(envPaths);
exit(0);
break;
case ECHO:
removeSingleQuotes(&reminder, false);
printf("%s\n", reminder);
break;
case TYPE:
typeFunction(reminder, envPaths);
break;
case PWD:
getcwd(cwd, sizeof(cwd));
printf("%s\n", cwd);
break;
case CD:
cdFunction(reminder);
break;
default:
removeSingleQuotes(&reminder, true);
systemOtherFunction(operation, reminder, envPaths);
}
fflush(stdout);
} while (1);
cleanup(envPaths);
return 0;
}