sing System.Diagnostics; // For Process
//string fileName = @"C:\WebBuild\nant-0.86-beta1\bin\NAnt.exe";
//string arguments = " -help";
//ProcessStartInfo startInfo = new ProcessStartInfo( fileName, arguments );
//startInfo.CreateNoWindow = false;
//startInfo.UseShellExecute = false;
////If this option is set the DOS window appear again
////startInfo.WindowStyle = ProcessWindowStyle.Hidden;
//startInfo.RedirectStandardOutput = true;
//string result = String.Empty;
//using (Process exeProcess = Process.Start( startInfo ))
//{
// result = exeProcess.StandardOutput.ToString(); ;
// exeProcess.WaitForExit();
//}
//string command = @"C:\WebBuild\nant-0.86-beta1\bin\NAnt.exe -help";
uxResult.Text = String.Empty;
string command = @"C:\WebBuild\nant-0.86-beta1\bin\NAnt.exe -buildfile:C:\WebBuild\vpaspSkin.build";
// create the ProcessStartInfo using "cmd" as the program to be run, and "/c " as the parameters.
// Incidentally, /c tells cmd that we want it to execute the command that follows, and then exit.
System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo( "cmd", "/c " + command );
// The following commands are needed to redirect the standard output.
//This means that it will be redirected to the Process.StandardOutput StreamReader.
//true
procStartInfo.RedirectStandardOutput = true;
// false
procStartInfo.UseShellExecute = false;
//If true Do not create the black window.
procStartInfo.CreateNoWindow = true;
// Now we create a process, assign its ProcessStartInfo and start it
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo = procStartInfo;
proc.Start();
// Get the output into a string
string result = proc.StandardOutput.ReadToEnd();
uxResult.Text = result;
// Display the command output.
//Console.WriteLine( result );
MessageBox.Show( "Success" );
From old code i have 2 solution to use shell command. this example is about build Nant by win form.
ไม่มีความคิดเห็น:
แสดงความคิดเห็น