title: Compiling C/C++/Visual C program by Command Line
body: <p>I wrote a program in C # - windows-forms
  Which receives input from the source code in C / C ++
  And I have to compile it and run, and show the user output according to his plan.
  The use of Microsoft's codedom compiling classes is not successful, after long Internet surfing, because the above-mentioned functions for C language are not being implemented.
  I created a program that opens the command line and sends commands to it, and reads the output back.
  Using Visual Studio's built-in command line was not successful because it closed immediately after a few seconds after it was opened and I could not find a solution to this even after a long search on the Internet.</p>
  
  <p><a href="https://i.stack.imgur.com/5XtLy.png" rel="nofollow noreferrer">You can see here my view </a></p>
  
  <pre><code>And this is the code:
  
        string vcvars32 = @"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\vcvars32.bat";
          string vsdevcmd = @"C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\VsDevCmd.bat";
          string WorkingDirectory = @"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin";
          string sourceFilePath = @"E:\C_Sources\sample.c";
  
   private void button1_Click(object sender, EventArgs e)
          {
              saveToFile(textBox1.Text);//Save the code as c file.
              textBox3.Text = runCmd();
          }
  
    string runCmd()
      {
          Process p = new Process();
          ProcessStartInfo info = new ProcessStartInfo();
          info.FileName = @"cmd.exe";
          info.RedirectStandardInput = true;
          info.UseShellExecute = false;
          info.RedirectStandardOutput = true;
          info.CreateNoWindow = true;
          p.StartInfo = info;
          p.Start();
  
          using (StreamWriter sw = p.StandardInput)
          {
              if (sw.BaseStream.CanWrite)
              {
                  sw.WriteLine(vsdevcmd );
                  sw.WriteLine("cd " + WorkingDirectory);
                  sw.WriteLine(vcvars32);
                  sw.WriteLine();
                  sw.Write("cl.exe ");
  
                  sw.WriteLine(sourceFilePath);
              }
          }
          using (StreamReader sr = p.StandardOutput)
          {
              if (sr.BaseStream.CanRead)
              {
                  toolStripStatusLabel1.Text = "Parse completed";
  
                  return sr.ReadToEnd();
              }
          }
  
          p.WaitForExit();
          toolStripStatusLabel1.Text = "cannot read output";
          return "";
      }
  </code></pre>
  
  <p>something works, 
  But I get an error like this:</p>
  
  <p>fatal error C1034: winsdkver.h: no include path set</p>
  
  <p>although i call the "vcvars32.bat" command, to load all environment variables.
  you can see it in the image.</p>
  
  <p>Thank you all for any help!!</p>