Help challenge Run a program on TypeScript

I’m stuck on Stage #ip1

I’ve tried debugging but the program thinks my debugging messages are the program output.

I think the problem is either Im not passing the correct path, or it is not finding the program. Which is weird because I used the same code to create the type builtin and that one works fine.

Here is my code

function promptUser() {
  rl.question("$ ", (answer) => {

    const param = answer.split(" ");

    const paths = (process.env.PATH || "").split(":");
    let found = false;
.
.
.
      // process.stdout.write(`Debugging paths: ${paths}\n`);
      for (const p of paths) {
        const fullPath = path.join(p, param[0]);
         //process.stdout.write(`Debugging fullpath: ${fullPath}\n`);
        if (require("fs").existsSync(fullPath)) {
            const command = `${param.join(" ")}`;
            process.stdout.write(`Executing command: ${command}\n`);
            exec(command, (error: { message: any; }, stdout: any, stderr: any) => {
            if (error) {
              rl.write(`error: ${error.message}\n`);
              return;
            }
            if (stderr) {
              rl.write(`stderr: ${stderr}\n`);
              return;
            }
            rl.write(`result: ${stdout}\n`);
            });
          found = true;
          break;
        }
      }

      if(!found) {
        rl.write(`${param[0]}: command not found\n`);
      }

Here are my logs:

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_6316
remote: [tester::#IP1] Running ./your_program.sh
remote: [your-program] $ custom_exe_6316 Maria
remote: [tester::#IP1] Output does not match expected value.
remote: [tester::#IP1] Expected: "$ custom_exe_6316 Maria"
remote: [tester::#IP1] Received: ""
remote: [your-program] $ result: Program was passed 2 args (including program name).result:: command not found
remote: [your-program] Debugging fullpath: /usr/local/bin/result:
remote: [your-program] $ result: Program was passed 2 args (including program name).result:: command not found
remote: [your-program] Debugging fullpath: /tmp/baz/result:
remote: [your-program] Debugging fullpath: /usr/local/sbin/result:
remote: [your-program] Debugging fullpath: /usr/local/bin/result:
remote: [your-program] Debugging fullpath: /usr/sbin/result:
remote: [your-program] Debugging fullpath: /usr/bin/result:
remote: [your-program] Debugging fullpath: /sbin/result:
remote: [your-program] Debugging fullpath: /bin/result:
remote: [your-program] $ result: Program was passed 2 args (including program name).result:: command not found

Entire repo can be found here:

Hi @davidceto1, could you upload your code to GitHub and share the link? It will be much easier to debug if I can run it directly.

Hi @andy1li Here is the repo:

Hey @davidceto1, sorry for the delayed response!

You can use execSync instead of exec for synchronous command execution, which might be preferable in the current context.

Closing this thread due to inactivity. If you still need assistance, feel free to reopen or start a new discussion!

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.