# \[C++\] #BR6 case passes without any code changes

**URL:** <https://forum.codecrafters.io/t/c-br6-case-passes-without-any-code-changes/12878>\
**Category:** Challenges\
**Tags:** challenge:shell\
**Created:** [June 30, 2025, 8:51pm UTC](https://forum.codecrafters.io/t/c-br6-case-passes-without-any-code-changes/12878 "2025-06-30T20:51:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sangeetsourav](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/sangeetsourav/32/6168_2.png) [@sangeetsourav](https://forum.codecrafters.io/u/sangeetsourav)\
**Post date:** [June 30, 2025, 8:51pm UTC](https://forum.codecrafters.io/t/c-br6-case-passes-without-any-code-changes/12878/1 "2025-06-30T20:51:18Z")

</div>

Hi,

I am not sure why but this case passed immediately without any code change from the previous stage (#WT6). Initially I thought it might be because of the readline library but I didn’t find any reference in the documentation that the library provides piping.

Can you point me towards what could possibly be the reason behind this?

---

<div class="post-metadata">

**Author:** ![senevoldsen](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/senevoldsen/32/6460_2.png) [@senevoldsen](https://forum.codecrafters.io/u/senevoldsen)\
**Post date:** [June 30, 2025, 10:10pm UTC](https://forum.codecrafters.io/t/c-br6-case-passes-without-any-code-changes/12878/4 "2025-06-30T22:10:06Z")

</div>

You don’t mention your language or how you are running the commands? Seen that quite some people just offload process running during that stage to the `int system(const char *string)` function instead of doing their own process launching. The entire challenge builds a shell that resembles Bash, and since the system shell on the test server is also Bash (or close enough), then when your shell receives `cat myfile.txt | wc` and if you end up passing it to `system` like `system("cat myfile.txt | wc")` then it is likely you will pass the tests.

---

<div class="post-metadata">

**Author:** ![sangeetsourav](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/sangeetsourav/32/6168_2.png) [@sangeetsourav](https://forum.codecrafters.io/u/sangeetsourav)\
**Post date:** [June 30, 2025, 10:23pm UTC](https://forum.codecrafters.io/t/c-br6-case-passes-without-any-code-changes/12878/5 "2025-06-30T22:23:18Z")

</div>

Hi,  
Thank you for your reply. I have mentioned my language in the title. It is C++.  
And you are absolutely right in that I am using std::system to run the command. Should I be running the commands in a different way (so that I don’t get the stage for free)?

---

<div class="post-metadata">

**Author:** ![senevoldsen](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/senevoldsen/32/6460_2.png) [@senevoldsen](https://forum.codecrafters.io/u/senevoldsen)\
**Post date:** [June 30, 2025, 10:44pm UTC](https://forum.codecrafters.io/t/c-br6-case-passes-without-any-code-changes/12878/6 "2025-06-30T22:44:16Z")

</div>

Silly me, you did indeed mention the language.

I can’t tell how far one can get with (std::)system function, or whether there will come some hard roadblocks up ahead. You have to quote the arguments you just spent time parsing to pass to system, to handle symbols and spaces in file names etc.. I think most passes the tests even with `system` because the test after command launching do not require much, if any, argument escaping.

And I don’t want to say that it is wrong, and people have their own reason for doing the challenges and what they hope to get out of it. Personally, though I find it antithetical to implement a shell by offloading the actual job to another shell—which is what `system` does. I don’t think there is a right answer, but I do think the intended answer for Linux is to use the [fork](https://man7.org/linux/man-pages/man2/fork.2.html), and [execve](https://man7.org/linux/man-pages/man2/execve.2.html) (or one of the other exec, maybe `execvp`) functions. To switch to these will be an initial hurdle, mostly with setting up redirection/file handles, but there are common idioms for doing this, and plenty of tutorials one can search for. I think [posix\_spawn](https://man7.org/linux/man-pages/man3/posix_spawn.3.html) handles both some of the nuances of fork/exec, but I don’t know if the testers support that; I suspect they do. And if you do this work would have more control over exactly what happens, and learned how OS process handling actually works.

---

<div class="post-metadata">

**Author:** ![sangeetsourav](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/sangeetsourav/32/6168_2.png) [@sangeetsourav](https://forum.codecrafters.io/u/sangeetsourav)\
**Post date:** [June 30, 2025, 10:46pm UTC](https://forum.codecrafters.io/t/c-br6-case-passes-without-any-code-changes/12878/7 "2025-06-30T22:46:37Z")

</div>

Thank you for the detailed answer. I think I will go ahead and try implementing the fork/exec combination.

---

<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:** [July 5, 2025, 10:46pm UTC](https://forum.codecrafters.io/t/c-br6-case-passes-without-any-code-changes/12878/9 "2025-07-05T22:46:39Z")

</div>

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