Recent

Author Topic: Stdout from program  (Read 13393 times)

tomek

  • Jr. Member
  • **
  • Posts: 85
Stdout from program
« on: March 08, 2011, 09:53:51 pm »
Is there any way to catch/redirect stdout of program in program ?
I want to get like debugln messages in my app (as ex. in Memo component) ? Something like catch self stdout.

eny

  • Hero Member
  • *****
  • Posts: 1634
Re: Stdout from program
« Reply #1 on: March 08, 2011, 10:13:04 pm »
All posts based on: Win10 (Win64); Lazarus 2.0.10 'stable' (x64) unless specified otherwise...

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me

tomek

  • Jr. Member
  • **
  • Posts: 85
Re: Stdout from program
« Reply #3 on: March 09, 2011, 08:15:17 am »
@leledumbo, you do not understand me, I want to catch self output.

@eny, thanks for hint, but it doesn't work, I also try with:
Code: [Select]
GetStdHandle(STD_OUTPUT_HANDLE)
 ReadConsoleOutputCharacter
and it's work only with nogui app (without -WG) or if I use AllocConsole before GetStdHandle(STD_OUTPUT_HANDLE).
It seams that it will work only with console.
I wonder how can help  --debug-log application parameter, which probably redirects STDOUT.
« Last Edit: March 09, 2011, 08:24:21 am by tomek »

eny

  • Hero Member
  • *****
  • Posts: 1634
Re: Stdout from program
« Reply #4 on: March 09, 2011, 09:59:14 am »
The question is: why do want to access stdout?
If it's for logging purposes it might be better to use a logging package like log4delphi (which has a FPC port).
All posts based on: Win10 (Win64); Lazarus 2.0.10 'stable' (x64) unless specified otherwise...

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1927
Re: Stdout from program
« Reply #5 on: March 09, 2011, 10:19:58 am »

tomek

  • Jr. Member
  • **
  • Posts: 85
Re: Stdout from program
« Reply #6 on: March 09, 2011, 10:21:03 am »
The question is: why do want to access stdout?
...

I use dll in the program, that dll provides only output as "print to stdout". And I want to have this output in gui app (without console). That's the problem.

eny

  • Hero Member
  • *****
  • Posts: 1634
All posts based on: Win10 (Win64); Lazarus 2.0.10 'stable' (x64) unless specified otherwise...

tomek

  • Jr. Member
  • **
  • Posts: 85
Re: Stdout from program
« Reply #8 on: March 09, 2011, 12:48:40 pm »
Google reveals this link: http://stackoverflow.com/questions/2639144/delphi-capture-stdout-and-stderr-output-from-statically-linked-msvc-compiled
That might help.

THANKS. That's it.
I use with Pipe, CreatePipe and SetStdHandle(STD_OUTPUT_HANDLE, hWriteToPipe) and I have output wherever I want.  :)

mirco

  • Newbie
  • Posts: 3
Re: Stdout from program
« Reply #9 on: May 17, 2017, 06:44:46 am »
Quote
I use with Pipe, CreatePipe and SetStdHandle(STD_OUTPUT_HANDLE, hWriteToPipe) and I have output wherever I want.  :)
Could you share your solution, please?
Thank you.

 

TinyPortal © 2005-2018