title: C++ system() not working when there are spaces in two different parameters
body: <p>I'm trying to run a .exe that requires some parameters by using system().</p>
  
  <p>If there's a space in the .exe's path AND in the path of a file passed in parameters, I get the following error:</p>
  
  <pre><code>The filename, directory name, or volume label syntax is incorrect.
  </code></pre>
  
  <p>Here is the code that generates that error:</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;conio.h&gt;
  
  int main (){
      system("\"C:\\Users\\Adam\\Desktop\\pdftotext\" -layout \"C:\\Users\\Adam\\Desktop\\week 4.pdf\"");
      _getch();
  }
  </code></pre>
  
  <p>If the "pdftotext"'s path doesn't use quotation marks (I need them because sometimes the directory will have spaces), everything works fine. Also, if I put what's in "system()" in a string and output it and I copy it in an actual command window, it works.</p>
  
  <p>I thought that maybe I could chain some commands using something like this:</p>
  
  <pre><code>cd C:\Users\Adam\Desktop;
  pdftotext -layout "week 4.pdf"
  </code></pre>
  
  <p>So I would already be in the correct directory, but I don't know how to use multiple commands in the same system() function.</p>
  
  <p>Can anyone tell me why my command doesn't work or if the second way I thought about would work?</p>
  
  <p><strong>Edit:</strong> Looks like I needed an extra set of quotation marks because system() passes its arguments to cmd /k, so it needs to be in quotations. I found it here:</p>
  
  <p><a href="https://stackoverflow.com/questions/7669433/c-how-to-make-a-my-program-open-a-exe-with-optional-args">C++: How to make a my program open a .exe with optional args</a></p>
  
  <p>so I'll vote to close as duplicate since the questions are pretty close even though we weren't getting the same error message, thanks!</p>