Jump to content
Roger Cigol

Win64 Starting an external exe and capturing the standard output text...

Recommended Posts

I have a C++ Builder (10.4.2) Windows 64 bit VCL application (clang64). Whilst it is running I want to start an external (third party) windows 64 bit exe console application and whilst this runs to completion I want my VCL application to capture (and I will write code to process) the) text output that the third party exe file sends to "standard output". Ideally I want to do this without the user being aware that it is happening.

 

It's easy to run an external console application in it's own shell, but how do I redirect the output from this external console application into my (already running) VCL application?

Share this post


Link to post

There are many Delphi units for doing that e.g.

-  JCL library in JclSysUtils Execute functions

- JVCL JvCreateProcess component 

and many others

Share this post


Link to post

If you don't want to rely on 3rd party wrappers, it is not very overly complicated to redirect the output and read it manually.  Just create a pipe, assign it to the STARTUPINFO passed to CreateProcess(), and then read from the pipe.  MSDN documents this task:

 

Creating a Child Process with Redirected Input and Output

Edited by Remy Lebeau
  • Like 1
  • Thanks 1

Share this post


Link to post

Thanks Remy - as you rightly say, it's not too difficult to get the console interface working. Slightly harder to write a unit test to prove that unicode chars are handled ok. But I got there in the end. Thanks for pointing me in the right direction.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×