I want to run a cmd and run some command in it. I wrote this code:
Process p = new Process();
ProcessStartInfo info =new ProcessStartInfo();
info.FileName = "cmd.exe";
info.WorkingDirectory = this.workingDirectory;
info.RedirectStandardInput = true;
info.UseShellExecute = false; 
info.CreateNoWindow = true;
p.StartInfo = info;
var x=p.Start();
using (StreamWriter sw = p.StandardInput)
{
    if (sw.BaseStream.CanWrite)
    {
        sw.WriteLine(@"set path=c:\temp"+ ";%path%");
        sw.WriteLine(@"@MyLongproces.exe");
    }
}
But it doesn't work:
info.CreateNoWindow to false).What is the problem? and how can I fix it?
This code doesn't work:
  string binDirectory = Path.Combine(FileSystem.ApplicationDirectory, this.binFolderName);
  ProcessStartInfo info = new ProcessStartInfo("cmd", @"/c " + Path.Combine(binDirectory, command));
  info.RedirectStandardInput = false;
  info.RedirectStandardOutput = true;
  info.UseShellExecute = false;
  info.CreateNoWindow = false;
  System.Diagnostics.Process proc = new System.Diagnostics.Process();
  proc.StartInfo = info;
  proc.Start();
  string result = proc.StandardOutput.ReadToEnd();
No cmd window is shown and result it "".
But this code works:
     Process.Start(Path.Combine(binDirectory, command));
The problem with above code is:
Any idea why it is not working?
You are setting the CreateNoWindow option:
info.CreateNoWindow = true;
ProcessStartInfo.CreateNoWindow - true if the process should be started without creating a new window to contain it; otherwise, false. The default is false.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With