Open Visual Studio command prompt from C# code
<p>I am trying to open Visual studio Command prompt using C# code.</p>

<p>Here is my code</p>

<pre><code>private void Execute(string vsEnvVar)
{

 var vsInstallPath = Environment.GetEnvironmentVariable(vsEnvVar);

 // vsEnvVar can be VS100COMNTOOLS, VS120COMNTOOLS, VS140COMNTOOLS

 if (Directory.Exists(vsInstallPath))
 {
    var filePath = vsInstallPath + "vsvars32.bat";
    if (File.Exists(filePath))
    {
        //start vs command process
        Process proc = new Process();

        var command = Environment.GetEnvironmentVariable("ComSpec");
        command = @"" + command + @"";

        var batfile = @"E:\Test\vstest.bat";
        var args = string.Format("/K  \"{0}\" \"{1}\"" ,filePath, batfile);  

        proc.StartInfo.FileName = command;
        proc.StartInfo.Arguments = args;
        proc.StartInfo.CreateNoWindow = false;
        proc.StartInfo.UseShellExecute = false;  

        proc.Start();
     }
     else
     {
        Console.WriteLine("File Does not exists " + filePath);
     }
 }
}
</code></pre>

<p>But the args string is not getting properly formatted.
I am getting below formatted string </p>

<pre><code>"/K  \"C:\\Program Files\\Microsoft Visual Studio 10.0\\Common7\\Tools\\vsvars32.bat\" \"E:\\Test\\vstest.bat\""    
</code></pre>

<p>extra "\" is getting added.</p>

<p>Please point out what I am missing.
Thanks</p>