# Redirect stdout quoting problem cpp

**URL:** https://forum.codecrafters.io/t/redirect-stdout-quoting-problem-cpp/15642
**Category:** Challenges
**Tags:** challenge:shell
**Created:** [December 9, 2025, 2:25pm UTC](https://forum.codecrafters.io/t/redirect-stdout-quoting-problem-cpp/15642 "2025-12-09T14:25:25Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![andrew-golarson](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andrew-golarson/32/20896_2.png) [@andrew-golarson](https://forum.codecrafters.io/u/andrew-golarson)
#### Post date: [December 9, 2025, 2:25pm UTC](https://forum.codecrafters.io/t/redirect-stdout-quoting-problem-cpp/15642/1 "2025-12-09T14:25:25Z")

</div>

I’m stuck on Stage **Redirect stdout** #jv1

Do I need to implement quoting for this to work? Idk if I messed up the order of the challenge, because it says I have to first do the redirecting.

Here are my logs:

```auto
remote: [your-program] $ ls -1 /tmp/fox > /tmp/ant/cow.md
remote: [your-program] $ cat /tmp/ant/cow.md
remote: [your-program] grape
remote: [your-program] pear
remote: [your-program] strawberry
remote: [tester::#JV1] ✓ Received redirected file content
remote: [your-program] $ echo 'Hello Emily' 1> /tmp/ant/fox.md
remote: [your-program] $ cat /tmp/ant/fox.md
remote: [your-program] 'Hello Emily'
remote: [tester::#JV1] ^ Line does not match expected value.
remote: [tester::#JV1] Expected: "Hello Emily"
remote: [tester::#JV1] Received: "'Hello Emily'"
remote: [your-program] $
remote: [tester::#JV1] Assertion failed.
remote: [tester::#JV1] Test failed

```

And here’s a snippet of my echo implementation:

```cpp
else if(command_name == "echo"){
      bool erase_one_more_space = false;
      std::string temp{};
      std::string message;
      while (ss >> temp) {
      if (temp == ">") {
        std_to_file = true;
        break;
      }else if(temp == "1>"){
        std_to_file = true;
        erase_one_more_space = true;
        break;
      }else{
        if(!message.empty()){
          message += " ";
        }
        message += temp;
      }
      }
      if(!std_to_file){
        std::cout << command.substr(5) << '\n'; 
      }else{
        std::string std_filename;
        if(ss >> std_filename){
        }else{
          std::cerr << "No filename provided";
          continue;
        }
        std::ofstream file(std_filename);
        file << message << '\n';
        file.close();
      }

```

---

<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: [December 9, 2025, 3:05pm UTC](https://forum.codecrafters.io/t/redirect-stdout-quoting-problem-cpp/15642/3 "2025-12-09T15:05:53Z")

</div>

You are just outputting the raw command past the first 5 chars. You are not parsing the arguments to echo, but are simply outputting it verbatim: `echo ‘123’ “456”` to `'123’ “456”` which is wrong.

The challenge as I recall have you parsing arguments in the very beginning so you might have skipped around.

---

<div class="post-metadata">

### Author: ![andrew-golarson](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andrew-golarson/32/20896_2.png) [@andrew-golarson](https://forum.codecrafters.io/u/andrew-golarson)
#### Post date: [December 9, 2025, 3:25pm UTC](https://forum.codecrafters.io/t/redirect-stdout-quoting-problem-cpp/15642/4 "2025-12-09T15:25:50Z")

</div>

Oh okay, thank you, maybe I misunderstood something in initial implementation;

---

<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: [December 14, 2025, 11:50pm UTC](https://forum.codecrafters.io/t/redirect-stdout-quoting-problem-cpp/15642/5 "2025-12-14T23:50:28Z")

</div>

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