# Issues running commands

**URL:** <https://forum.codecrafters.io/t/issues-running-commands/4414>\
**Category:** Challenges\
**Tags:** challenge:shell\
**Created:** [January 23, 2025, 10:42am UTC](https://forum.codecrafters.io/t/issues-running-commands/4414 "2025-01-23T10:42:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fruitpunch44](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/fruitpunch44/32/3539_2.png) [@Fruitpunch44](https://forum.codecrafters.io/u/Fruitpunch44)\
**Post date:** [January 23, 2025, 10:42am UTC](https://forum.codecrafters.io/t/issues-running-commands/4414/1 "2025-01-23T10:42:11Z")

</div>

I’m stuck on Stage Run a program #ip1

I created a function that executes the commands based on the path and arguments passed in but i don’t quite understand why it isn’t printing out the program signature and args  
although the program works normally locally to run normal commands.

Here are my logs:

```auto
[compile] Moved ./.codecrafters/run.sh → ./your_program.sh
[compile] Compilation successful.
[tester::#IP1] Running tests for Stage #IP1 (Run a program)
[tester::#IP1] [setup] export PATH=/tmp/foo:$PATH
[tester::#IP1] [setup] Available executables:
[tester::#IP1] [setup] - custom_exe_1177
[tester::#IP1] Running ./your_program.sh
[your-program] $ custom_exe_1177 David
[your-program] $ Program was passed 2 args (including program name).
[tester::#IP1] Output does not match expected value.
[tester::#IP1] Expected: "Program was passed 2 args (including program name)."
[tester::#IP1] Received: "$ Program was passed 2 args (including program name)."
[your-program] Arg #0 (program name): custom_exe_1177
[your-program] Arg #1: David
[your-program] Program Signature: 2588132668
[tester::#IP1] Assertion failed.
[tester::#IP1] Test failed (try setting 'debug: true' in your codecrafters.yml to see more details)
include relevant logs here (please make sure to keep the backticks around this!)

```

And here’s a snippet of my code:

```c
void execute_program(char *path,char **arguments){
  pid_t pid,pid2;//one for the fork process and another to return the process id
  pid=fork();
  pid2=getpid();
  if(pid==0){
    execv(path,arguments);
    for(int i=0;arguments[i]!=NULL;i++){
      printf("Arg #0: %s",arguments[0]);
      printf("Arg #1: %s",arguments[1]);
      printf("program signature: %d",pid2);}
    //execv doesn't return anything
    perror("no such directory");
    exit(1);
  }
else if(check_for_built_in(arguments)==0){
    char **args=split_line(input);
    /*printf("commands \n");
    for (int i = 0; args[i] != NULL; i++) {
      printf("%s\n", args[i]);}*/

    char *path=find_in_path(arguments);
    execute_program(path,args);
  }

include relevant code here (please make sure to keep the backticks around this!)

```

local output

```c

$ ls -l
$ total 4
drwxr-xr-x 1 Olu-Ade Olu-Ade 0 Jan 20 21:43 build 
-rw-r--r-- 1 Olu-Ade Olu-Ade 3840 Jan 23 11:31 main.c

```

here is the link to the repo

> **[GitHub - Fruitpunch44/codecrafters-shell-c](https://github.com/Fruitpunch44/codecrafters-shell-c)**
>
> Contribute to Fruitpunch44/codecrafters-shell-c development by creating an account on GitHub.

---

<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:** [January 23, 2025, 11:56am UTC](https://forum.codecrafters.io/t/issues-running-commands/4414/2 "2025-01-23T11:56:33Z")

</div>

Hi @Fruitpunch44, the task is to run an executable file such as “`custom_exe_1234`”, so there’s no need to implement it manually:

```auto
for(int i=0;arguments[i]!=NULL;i++){
      printf("Arg #0: %s",arguments[0]);
      printf("Arg #1: %s",arguments[1]);
      printf("program signature: %d",pid2);}

```

* * *

Another issue is that there’s an extra "`$ `" printed out:

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

* * *

I tried running your code against the previous stages, but it’s actually no longer passing the second stage **#CZ2 (Handle invalid commands)**.

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

Suggestions:

1. Use [our CLI](https://docs.codecrafters.io/cli/installation) to test against previous stages by running:

```auto
codecrafters test --previous

```

1. Focus on fixing the early stages first, as later stages depend on them.

---

<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:** [March 10, 2025, 9:46am UTC](https://forum.codecrafters.io/t/issues-running-commands/4414/3 "2025-03-10T09:46:49Z")

</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:** [March 15, 2025, 9:47am UTC](https://forum.codecrafters.io/t/issues-running-commands/4414/4 "2025-03-15T09:47:19Z")

</div>

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