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熱心網友回復:
可以把你們的C#程式改為函式,生成DLL供對方PB呼叫;引數最好都轉換為string,如有多個回傳引數,其他引數加ref具體步驟可參考:
http://blog.csdn.net/nocry115/article/details/52851722
uj5u.com熱心網友回復:
我們設計成了exe被其他系統呼叫,可能是vb,也可能使pb,或者是C#、C++。
uj5u.com熱心網友回復:
可以寫到文本檔案中啊,呼叫完從文本檔案中獲取執行結果就可以了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/24665.html
標籤:基礎類
上一篇:如何動態通過代碼來設定 DW資料視窗某行與某行某列字體的顏色
下一篇:讀考勤資料
