Redirect stdout quoting problem cpp

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:

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:

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();
      }

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.

2 Likes

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

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