作为自动化BizTalk部署的一部分,我使用以下代码从c#运行进程。
string commandArguments =
"ImportApp /ApplicationName:"" + ApplicationFullName +
"" /Package:"" + MsiFilePath+ """;
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.FileName = "BTSTask.exe";
p.StartInfo.Arguments = commandArguments;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
StreamReader outputStream = p.StandardOutput;
StreamReader errorStream = p.StandardError;
// Read the standard output
//string output = outputStream.ReadToEnd();
string error = errorStream.ReadToEnd();
//WriteToLogFile(output);
if (!error.Equals(""))
{
WriteToLogFile(error);
throw new Exception("Error occurred while importing application " +
ApplicationFullName +
Environment.NewLine +
error);
}
p.WaitForExit();
p.Close();
return;
我在日志文件中得到的这个过程的输出看起来像这样:
Copyright (c) 2010 Microsoft Corporation. All rights reserved.
Information: Importing package "\tc6218BizTalkReceiveDropservernameAppsCore.Artifacts.msi" into application "Core.Artifacts" in BizTalk configuration database (server="TC6218", database="BizTalkMgmtDb")...
Information: Performing action "Create" on host "ConfigurationDb" using package "\ AppsCore.Artifacts.msi".
Information: Validating resources (count=6)...
* Validating resource (-Type="System.BizTalk:Assembly" -Luid="TC.BizTalk.Functoid.AdvancedDatabaseLookup, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f68c7d112162f09d")...
* Validating resource (-Type="System.BizTalk:Assembly" -Luid="TaylorCorp.Erp.ServiceBus.MasterData.Components.BusinessRules, Version=1.0.0.2, Culture=neutral, PublicKeyToken=f68c7d112162f09d")...
* Validating resource (-Type="System.BizTalk:BizTalkAssembly" -Luid="ICSM.Schemas, Version=4.0.1.0, Culture=neutral, PublicKeyToken=69c11018615fef04")...
* Validating resource (-Type="System.BizTalk:BizTalkAssembly" -Luid="ICSM.Pipelines, Version=4.0.1.0, Culture=neutral, PublicKeyToken=69c11018615fef04")...
* Validating resource (-Type="System.BizTalk:BizTalkAssembly" -Luid="ICSM.Maps, Version=2.0.0.0, Culture=neutral, PublicKeyToken=69c11018615fef04")...
* Validating resource (-Type="System.BizTalk:BizTalkBinding" -Luid="Application/Core.Artifacts")...
Information: Performing change requests...
Information: Calling BeginTypeChangeRequest for all selected resource types...
PerformingBeginChangeRequest
PerformingBeginChangeRequest
PerformingBeginChangeRequest
Adding resource (-Type="System.BizTalk:Assembly" -Luid="TC.BizTalk.Functoid.AdvancedDatabaseLookup, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f68c7d112162f09d") to store.
Information: PerformingEndChangeRequestsWithRollBack
* Performing EndTypeChangeRequest for resource type "System.BizTalk:Assembly".
* Performing EndTypeChangeRequest for resource type "System.BizTalk:BizTalkAssembly".
* Performing EndTypeChangeRequest for resource type "System.BizTalk:BizTalkBinding".
Error: Resource (-Type="System.BizTalk:Assembly" -Luid="TC.BizTalk.Functoid.AdvancedDatabaseLookup, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f68c7d112162f09d") already in store.
1) Use BTSTask's overwrite flag or
2) Set redeploy flag to true in BizTalk Project or
3) Click overwrite all checkbox in Admin MMC
to update if the resource exists in the specified target application "Core.Artifacts".
Overwrite flag will be ignored if the resource is associated with another application.
Command failed with 1 errors, 0 warnings.
现在,我需要做的就是找出进程是否出错。并且,我需要将输出流和错误流都存储到字符串变量中。(我不想解析这个字符串,你现在可能知道了。我不希望遇到微软所说的"死锁"问题,在这种情况下,我完全不理解。
谢谢你的帮助!
根据:http://msdn.microsoft.com/en-us/library/aa559686 (v = bts.20) . aspx
bttask .exe进程如果成功返回0,如果有问题返回非0。此返回代码将显示在您的p.ExitCode
想到三个解决方案:
- 订阅进程。ErrorDataRecieved事件。 从进程中获取返回错误代码。通常如果它不是0,这是一个关于错误的信号。
- 分析你的进程是否在StandartOutput上报告错误,并通过分析你的"keywords"来读取这个字符串。
不幸的是,使用单独的过程,你"失去"了控制,因此必须在项目的架构过程中基于决策的可靠架构和容错性之间进行平衡。
希望这对你有帮助。
问候。