问题描述
我要precompile在我定制的C#形式的asp.net应用程序。如何检索过程日志,并检查它是否是一个成功的过程与否?
I'm going to precompile an asp.net application in my custom c# form. How do i retrieve the process logs and check whether it is a successful process or not?
下面是我的code
string msPath = "c:\\WINDOWS\\Microsoft.NET\\Framework\\v2.0.50727\\";
string msCompiler = "aspnet_compiler.exe";
string fullCompilerPath = Path.Combine(msPath, msCompiler);
msPath.ThrowIfDirectoryMissing();
fullCompilerPath.ThrowIfFileIsMissing();
ProcessStartInfo process = new ProcessStartInfo
{
CreateNoWindow = false,
UseShellExecute = false,
WorkingDirectory = msPath,
FileName = msCompiler,
Arguments = "-p {0} -v / {1}"
.StrFormat(
CurrentSetting.CodeSource,
CurrentSetting.CompileTarget)
};
Process.Start(process);
谢谢!
推荐答案
设置 ProcessStartInfo.RedirectStandardOutput
以真正
- 这将重定向所有输出到 Process.StandardOutput
,这是一个流,你可以阅读查找所有输出消息:
Set your ProcessStartInfo.RedirectStandardOutput
to true
- this will redirect all output to Process.StandardOutput
, which is a stream that you can read to find all output messages:
ProcessStartInfo process = new ProcessStartInfo
{
CreateNoWindow = false,
UseShellExecute = false,
WorkingDirectory = msPath,
RedirectStandardOutput = true,
FileName = msCompiler,
Arguments = "-p {0} -v / {1}"
.StrFormat(
CurrentSetting.CodeSource,
CurrentSetting.CompileTarget)
};
Process p = Process.Start(process);
string output = p.StandardOutput.ReadToEnd();
您也可以用类似的方法是什么@Bharathķ描述了他的答案使用 OutputDataReceived
事件。
You can also use the OutputDataReceived
event in a similar way to what @Bharath K describes in his answer.
有用于 StandardError的
相似的属性/事件 - 你将需要设置 RedirectStandardError
到真正
以及
There are similar properties/events for StandardError
- you will need to set RedirectStandardError
to true
as well.
这篇关于如何获得记录来自的Process.Start的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!