我正在尝试从C#应用程序调用ant脚本.我希望控制台窗口弹出并保持正常(我现在只是调用命令提示符,但我最终想调用一个蚂蚁脚本,这可能需要长达一个小时).这是我正在使用的代码,我从原来改变了:
public void ExecuteCommandSync(object command)
{
try
{
// 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", "/k " + command);
// The following commands are needed to redirect the standard output.
// This means that it will be redirected to the Process.StandardOutput StreamReader.
procStartInfo.RedirectStandardOutput = true;
procStartInfo.UseShellExecute = false;
// Do not create the black window.
procStartInfo.CreateNoWindow = false;
// Now we create a process, assign its ProcessStartInfo and start it
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo = procStartInfo;
proc.Start();
proc.WaitForExit();
}
catch (Exception objException)
{
Console.WriteLine(objException);
}
}
Run Code Online (Sandbox Code Playgroud)
我还想传递最多5个参数,但是现在我只关心保持窗口打开足够长的时间以查看正在发生的事情,而且我对阅读由ant脚本生成的任何内容不感兴趣.我不想让任何人为我做我的工作,但我已经在这个问题上敲了一会儿,所以任何帮助都将不胜感激!
这条线;
procStartInfo.RedirectStandardOutput = true;
Run Code Online (Sandbox Code Playgroud)
是什么导致窗口关闭.删除此行,或向Process.StandardOutput添加处理程序以读取其他位置的内容;
string t = proc.StandardOutput.ReadToEnd();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13114 次 |
| 最近记录: |