Use the pipeline redirection method to obtain the command line execution program results in Windows

Source: Internet
Author: User

KeyCode:

Void credirectpipedlg: onbnclickedruncmd () <br/> {<br/> // todo: add your control notification handler Code <br/> updatedata (); <br/> m_stroutput = ""; <br/> security_attributes SA; <br/> handle hread, hwrite; <br/> SA. nlength = sizeof (security_attributes); <br/> SA. lpsecuritydescriptor = NULL; <br/> SA. binherithandle = true; <br/> If (! Createpipe (& hread, & hwrite, & SA, 0) <br/>{< br/> MessageBox (_ T ("error on createpipe ()")); <br/> return; <br/>}< br/> startupinfo Si; <br/> process_information PI; <br/> Si. CB = sizeof (startupinfo); <br/> getstartupinfo (& Si); <br/> Si. hstderror = hwrite; <br/> Si. hstdoutput = hwrite; <br/> Si. wshowwindow = sw_hide; <br/> Si. dwflags = startf_useshowwindow | startf_usestdhandles; <br/> cstring strcmd (_ T ("CMD/C/" ") + m_strcmd + _ T ("/""); <br/> If (! CreateProcess (null, (lpstr) strcmd. getstring (), null, null, true, null, & Si, & PI )) <br/>{< br/> MessageBox (_ T ("error on CreateProcess ()"); <br/> return; <br/>}< br/> closehandle (hwrite); <br/> char buffer [1, 4096] = {0}; <br/> DWORD bytesread; <br/> while (true) <br/> {<br/> If (readfile (hread, buffer, 4095, & bytesread, null) = NULL) <br/> break; <br/> m_stroutput + = buffer; <br/> memset (buffer, 0, 4096); <br/> updatedata (false ); <br/> sleep (200); <br/>}< br/>}

 

 

:

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.