How can I call the console program? 1. Hide the console window; 2. Obtain the exit status of the console program.

Source: Internet
Author: User
Shadowwind (Lily has died) 17:22:25 on VC/MFC/ Basic ClassHow to call the console program: 1. Hide the console window; 2. Get the exit status of the console Program

I use system and _ spawnlp. The returned value is exit code, but the window cannot be hidden.
Windows can be hidden with winexec (command, sw_hide), but no exit code is available.

Thank you for your advice ~ Number of questions: 100, replies: 6

Keiy () on the first floor replied to 17:37:04 score 0 use CreateProcess + getexitcodeprocess to try

Top

Wly033 (ming) on the second floor: reply to 18:06:31 score 5 CreateProcess + waitforsingleobject + getexitcodeprocess

Top

Subtop (seeking job...) on the third floor replied to 18:44:58 score 5. Try the upstairs method.

Top

On the 4th floor, keiy () replied to the error: 19:04:11 score 0. I tried it. I have a problem.
CreateProcess if startf_useshowwindow + sw_hide is used
Waitforsingleobject does not return
Getexitcodeprocess does not return values either.
If you do not need startf_useshowwindow, you can get the exitcode normally.

Top

On the fifth floor, keiy () replied to the success score of 90 at 19:48:06:
Process_information PI;
Startupinfo Si;

// Set up the start up info struct.
Zeromemory (& Si, sizeof (startupinfo ));

Si. dwflags = startf_useshowwindow;
Si. wshowwindow = sw_hide;

CreateProcess (null, "d: // temp // t.exe", null, null, 0,
Null, null, null, & Si, & PI );
Waitforsingleobject (PI. hthread, infinite );
Closehandle (PI. hthread );
DWORD excode = 0;
Getexitcodeprocess (PI. hprocess, & excode );
// Excode is returned

Top

The keiy () on the sixth floor is replied to the score of 0 at 19:51:23,. In addition, Si. wshowwindow = sw_hide; save
(Because the value of sw_hide is 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.