Normally, winform cannot obtain the returned value of exe. In this case, I use the method to write the value in EXE to the CSV file, and then winform reads the CSV file.
Private void btngoodsselect_click (Object sender, eventargs E)
{
Parameterizedthreadstart PTS = new parameterizedthreadstart (runcommand );
Thread firstchildthread = new thread (PTS );
Firstchildthread. start ("apsi.exe h111601010102i. PSP + Arg-B "+ basescode +"-G "+ txtgoods. text. tostring () + "-s" + goodssegment + "");
}
/// <Summary>
/// Execute the commond command
/// </Summary>
/// <Param name = "commandname"> commandname </param>
Public void runcommand (Object commandname)
{
If (process = NULL)
{
Process = new process ();
Process. startinfo. filename = "cmd.exe"; // determine the program name
Process. startinfo. Arguments = "/C" + commandname; // determine the program command line
Process. startinfo. useshellexecute = false; // use of Shell
Process. startinfo. redirectstandardinput = true; // redirect Input
Process. startinfo. redirectstandardoutput = true; // redirect the output
Process. startinfo. redirectstandarderror = true; // redirect Output Error
Process. startinfo. createnowindow = true; // you can specify not to display a window.
Process. exited + = new eventhandler (p_exited); // call at the end of Process
Process. enableraisingevents = true;
Process. Start ();
Process. waitforexit ();
Process. Close ();
Process. Dispose ();
Process = NULL;
}
}
/// <Summary>
/// Custom process exit event
/// </Summary>
/// <Param name = "sender"> </param>
/// <Param name = "E"> </param>
Private void p_exited (Object sender, eventargs E)
{
// Create a delegate. The managed code of invokefun
Methodinvoker MI = new methodinvoker (this. invokefun );
This. begininvoke (MI); // asynchronous execution delegate;
}
/// <Summary>
/// Delegate mi hosting code
/// </Summary>
Private void invokefun ()
{
Streamreader sr = new streamreader ("C: \ test.csv", encoding. Default );
String S = "";
While (S = Sr. Readline ())! = NULL)
{
String [] STR = S. Split (',');
This.txt goods. Text = STR [0]. Replace ("\"","");
This. goodssegment = STR [2]. Replace ("\"","");
}
Sr. Close ();
Goodscheck ();
This.txt goods. Focus ();
This.txt goods. selectionstart = 0;
}