PB我沒接觸過,但所做的專案中涉及到:PB呼叫C#寫的EXE。這個C#的EXE是我們公司寫的,PB是另外公司,需要讓對方來呼叫我們的EXE,呼叫時候規定了XML輸入引數,執行完EXE后,PB需要獲取EXE給他的XML格式回傳值,在呼叫程序中,我們公司會有一些業務流程表單互動。
請高手來幫忙解決!
C#代碼EXE服務執行程式(ConsoleApp.exe)樣例代碼的如下:
static void Main(string[] args)
{
string procName = System.Diagnostics.Process.GetCurrentProcess().ProcessName;
File.AppendAllText("D:\\systemtool.txt", procName + "\n");
if ((System.Diagnostics.Process.GetProcessesByName(procName)).GetUpperBound(0) == 0)
{
File.AppendAllText("D:\\systemtool.txt", "Bussiness handle" + "\n");
//接收傳過來的XML格式字串引數
string paramXML = "";
if (!string.IsNullOrEmpty(args[0]))
{
paramXML = args[0];
File.AppendAllText("D:\\systemtool.txt", "Input XML parameters:" + paramXML + "\n");
XmlDocument oXmlDoc = new XmlDocument();
try
{
oXmlDoc.LoadXml(paramXML);
XmlNode root = oXmlDoc.DocumentElement;
XmlNodeList nodes = root.ChildNodes;
foreach (XmlNode node in nodes)
{
File.AppendAllText("D:\\systemtool.txt", node.Name + "->" + node.InnerText + "\n\n");
}
//呼叫其他業務表單代碼
.................
}
catch (Exception error)
{
File.AppendAllText("D:\\systemtool.txt", "Exception error->" + error.Message + "\n");
throw new Exception(error.Message);
}
finally
{
oXmlDoc = null;
}
}
//回傳值
string returnParam = "<Root><RetValue>1</RetValue></Root>";
Console.Write(returnParam);//將回傳值寫入到標準的控制臺輸出。
}
C#呼叫EXE執行程式樣例,如下:
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
//外部Console服務程式物理路徑
p.StartInfo.FileName = @"F:\ConsoleApp.exe";
p.StartInfo.CreateNoWindow = true;
//啟動引數
p.StartInfo.Arguments = "<Root><Inparam>0</Inparam></Root>";
p.Start();
p.WaitForExit();
//回傳值
string returnValue = p.StandardOutput.ReadToEnd();
uj5u.com熱心網友回復:
請高手幫忙撰寫測驗通過的原始碼貼上,非常感謝,著急用!uj5u.com熱心網友回復:
為啥發2遍?請參考:http://blog.csdn.net/nocry115/article/details/52851722uj5u.com熱心網友回復:
感謝參考提供,但我需要的是呼叫EXE,而不是dll。
uj5u.com熱心網友回復:
寫文本檔案,我也發2次uj5u.com熱心網友回復:
不能用資料庫和文本
uj5u.com熱心網友回復:
把輸出重定向到一個檔案里,試試以下代碼run("f:\consoleapp.exe '<Root><Inparam>0</Inparam></Root>' >> c:\111.txt")
然后再pb里打開c:\111.txt進行處理
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/24669.html
標籤:API 調用
上一篇:讀考勤資料
下一篇:pb90 呼叫webservice報錯 Unexpected return Content-Type: text/html
