C # winform calls the EXE file in other languages and obtains the return value

Source: Internet
Author: User

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;
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.