You ask a terminal to run a tool. Where is that tool, and did it finish successfully? Built-in commands alone cannot answer those questions. The shell needs a way to locate a program and report its result without disappearing when it fails.
Extend your command loop with which and run. Separate a program's output from its exit status and keep reading commands afterward. This judge uses fixed program results, not real process creation.
Input: Command lines containing which <name>, run <name> [arguments...], or exit. The judged examples use whitespace-separated words.
Output: which prints the modeled path or NOT_FOUND. run prints any program output, then [Process exited with code N] on its own line. exit is silent.
Input:
run echo test exit
Output:
test [Process exited with code 0]
Explanation: The program prints test; the shell separately reports exit code 0. Program output and completion status are different pieces of information.
Input:
run /bin/notexist exit
Output:
No such file or directory [Process exited with code 127]
Explanation: The missing program produces an error and code 127. A failed run is still a result the shell must handle.
Input:
run false exit
Output:
[Process exited with code 1]
Explanation: false produces no text, but code 1 tells us it did not succeed. Empty output is not proof of success.
Input:
which ls exit
Output:
/bin/ls
Explanation: which asks where ls is modeled to live. It prints /bin/ls without running ls.
Input:
run echo one run echo two exit
Output:
one [Process exited with code 0] two [Process exited with code 0]
Explanation: After the first run finishes, the shell handles the second. Each run gets its own output and status.
Paste this into Custom Input and run your solution.
run false run echo still here exit
Does the first program's failure stop the shell?
Expected output:
[Process exited with code 1] still here [Process exited with code 0]
No. Code 1 describes false, not the shell session. The parent loop continues, processes echo, and stops only at exit or end of input.
Can you handle program output and exit status as two separate results?
Real shells look up executables and launch child processes. This exercise teaches their command/result interface using controlled fixtures, not unrestricted process creation.
Distinguish running work from finished work without ending the shell.
test [Process exited with code 0]