(Java) #IP1 Fails But Output Looks Ok

I’m stuck on Stage #IP1.

I’ve tried the following method to execute an external command:

    List<String> argsWithCommandName = new ArrayList<>(arguments);
    argsWithCommandName.addFirst(commandName);
    
    ProcessBuilder processBuilder = new ProcessBuilder(argsWithCommandName);
    
    try {
      Process process = processBuilder.start();
      process.waitFor();
      
      String output = inputStreamToString(process.getInputStream());
      
      System.out.println(output);
    } catch (Exception e) {
    }

Here are my logs:

remote: [compile] Compilation successful.
remote:
remote: Debug = true
remote:
remote: [tester::#IP1] Running tests for Stage #IP1 (Run a program)
remote: [tester::#IP1] [setup] export PATH=/tmp/baz:$PATH
remote: [tester::#IP1] [setup] Available executables:
remote: [tester::#IP1] [setup] - custom_exe_9420
remote: [tester::#IP1] Running ./your_program.sh
remote: [your-program] $ custom_exe_9420 David
remote: [your-program] Program was passed 2 args (including program name).
remote: [your-program] Arg #0 (program name): custom_exe_9420
remote: [your-program] Arg #1: David
remote: [your-program] Program Signature: 3357538634
remote: [tester::#IP1] Expected prompt ("$ ") but received ""
remote: [your-program] $
remote: [tester::#IP1] Assertion failed.
remote: [tester::#IP1] Test failed

I don’t understand why my output would show the proper prompt but the tester says it isn’t there. Maybe it’s something with how Process handles streams?

Thank you!

Hey @BHSDuncan, it’s common for an extra newline to trigger the error Expected prompt ("$ ") but received "".

Keep in mind that System.out.println() automatically appends a newline, which can cause this error.

I feel like a bit of a tool for missing that. It was a poor assumption on my part to dump the output with println. Thank you for the sanity check! That’s what I get for looking at code for too long.

Enjoying your challenges. Thanks again for the help!

No worries at all! It happens to the best of us. Feel free to reach out anytime you get stuck again.