# Help challenge Run a program on TypeScript

**URL:** <https://forum.codecrafters.io/t/help-challenge-run-a-program-on-typescript/4966>\
**Category:** Challenges\
**Tags:** challenge:shell\
**Created:** [February 18, 2025, 5:53am UTC](https://forum.codecrafters.io/t/help-challenge-run-a-program-on-typescript/4966 "2025-02-18T05:53:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![davidceto1](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/davidceto1/32/5053_2.png) [@davidceto1](https://forum.codecrafters.io/u/davidceto1)\
**Post date:** [February 18, 2025, 5:53am UTC](https://forum.codecrafters.io/t/help-challenge-run-a-program-on-typescript/4966/1 "2025-02-18T05:53:08Z")

</div>

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

```auto
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:

```auto
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:

> **[GitHub - davidceto1/codecrafters-shell-typescript: codecrafters shell typescript challenge](https://github.com/davidceto1/codecrafters-shell-typescript)**
>
> codecrafters shell typescript challenge

---

<div class="post-metadata">

**Author:** ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)\
**Post date:** [February 18, 2025, 11:21am UTC](https://forum.codecrafters.io/t/help-challenge-run-a-program-on-typescript/4966/2 "2025-02-18T11:21:23Z")

</div>

Hi @davidceto1, could you [upload your code to GitHub](https://docs.codecrafters.io/features/publish-to-github) and share the link? It will be much easier to debug if I can run it directly.

---

<div class="post-metadata">

**Author:** ![davidceto1](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/davidceto1/32/5053_2.png) [@davidceto1](https://forum.codecrafters.io/u/davidceto1)\
**Post date:** [February 19, 2025, 12:18am UTC](https://forum.codecrafters.io/t/help-challenge-run-a-program-on-typescript/4966/5 "2025-02-19T00:18:27Z")

</div>

Hi @andy1li Here is the repo:

> **[GitHub - davidceto1/codecrafters-shell-typescript: codecrafters shell typescript challenge](https://github.com/davidceto1/codecrafters-shell-typescript)**
>
> codecrafters shell typescript challenge

---

<div class="post-metadata">

**Author:** ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)\
**Post date:** [April 23, 2025, 8:01am UTC](https://forum.codecrafters.io/t/help-challenge-run-a-program-on-typescript/4966/7 "2025-04-23T08:01:56Z")

</div>

Hey @davidceto1, sorry for the delayed response!

 ![image](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/2X/f/f85f1f91d97aa182532857054c9dba16b0d208c1.png)

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

---

<div class="post-metadata">

**Author:** ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)\
**Post date:** [May 4, 2025, 7:39pm UTC](https://forum.codecrafters.io/t/help-challenge-run-a-program-on-typescript/4966/9 "2025-05-04T19:39:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/3X/7/0/700657133935c15703e22c7c8870394f6e6dc27d.svg) [@system](https://forum.codecrafters.io/u/system)\
**Post date:** [May 9, 2025, 7:39pm UTC](https://forum.codecrafters.io/t/help-challenge-run-a-program-on-typescript/4966/10 "2025-05-09T19:39:34Z")

</div>

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