G
Guest
Hi,
I'm relatively new to C# so apopogies in advance if I am missing something
obvious. I am trying to run a command, which I would normally run from the
command line, from within my C# application. Here is my code:
private void FileMonitor_Changed(object sender,
System.IO.FileSystemEventArgs e)
{
string renamed = e.FullPath;
System.Diagnostics.Process process1;
process1= new System.Diagnostics.Process();
process1.EnableRaisingEvents = false;
string strCmdLine;
strCmdLine = "/C Dumper.exe \"" + renamed + "\"";
// MessageBox.Show("");
process1.StartInfo.FileName = "CMD.exe";
process1.StartInfo.Arguments = strCmdLine;
process1.StartInfo.UseShellExecute = false;
process1.StartInfo.RedirectStandardOutput = true;
process1.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process1.StartInfo.CreateNoWindow = true;
process1.Start();
StreamReader myStreamReader = process1.StandardOutput;
string rdfID = myStreamReader.ReadLine();
process1.Close();
}
The command fails to execute. However, if I were to uncomment
"MessageBox.Show("");" then the command executes correctly. I do not want to
pause my application with a message box, however.
Any ideas as to where I am going wrong? Many thanks in advance.
I'm relatively new to C# so apopogies in advance if I am missing something
obvious. I am trying to run a command, which I would normally run from the
command line, from within my C# application. Here is my code:
private void FileMonitor_Changed(object sender,
System.IO.FileSystemEventArgs e)
{
string renamed = e.FullPath;
System.Diagnostics.Process process1;
process1= new System.Diagnostics.Process();
process1.EnableRaisingEvents = false;
string strCmdLine;
strCmdLine = "/C Dumper.exe \"" + renamed + "\"";
// MessageBox.Show("");
process1.StartInfo.FileName = "CMD.exe";
process1.StartInfo.Arguments = strCmdLine;
process1.StartInfo.UseShellExecute = false;
process1.StartInfo.RedirectStandardOutput = true;
process1.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process1.StartInfo.CreateNoWindow = true;
process1.Start();
StreamReader myStreamReader = process1.StandardOutput;
string rdfID = myStreamReader.ReadLine();
process1.Close();
}
The command fails to execute. However, if I were to uncomment
"MessageBox.Show("");" then the command executes correctly. I do not want to
pause my application with a message box, however.
Any ideas as to where I am going wrong? Many thanks in advance.