Redirection of a process output

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
bertolino
Experienced Solver
Experienced Solver
Posts: 77
Joined: Wed Aug 14, 2013 8:07 am
Location: France
Contact:

Redirection of a process output

Post by bertolino »

My application needs to launch an external process in a clean way (in this case FFprobe) to get its output via a file.
It's easy to get the file on the command line using a redirection:

Code: Select all

ffprobe... > output.txt
But the thing is that wxExecute doesn't handle redirection and I do not want to use wxSystem since it shows the console (which is not clean).
The application is under Windows.
Any suggestion?
Have a good day,

Pascal
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: Redirection of a process output

Post by PB »

I did not try but I think you can call wxExecute() with "cmd /c ffprobe... > output.txt" as the command and it should work? Is the console really still shown even when using wxEXEC_HIDE_CONSOLE ?
Last edited by PB on Mon Apr 12, 2021 3:18 pm, edited 1 time in total.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Redirection of a process output

Post by ONEEYEMAN »

Hi,
wxLogXXX?

Thank you.
User avatar
doublemax
Moderator
Moderator
Posts: 19115
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Redirection of a process output

Post by doublemax »

But the thing is that wxExecute doesn't handle redirection
Really? What about wxProcess::Redirect(), wxProcess::GetInputStream(), wxProcess::GetOutputStream() etc?

You need to subclass wxProcess, create an instance of it and pass it to wxExecute. Check the "exec" sample, look for occurrences of "MyPipedProcess".
Use the source, Luke!
bertolino
Experienced Solver
Experienced Solver
Posts: 77
Joined: Wed Aug 14, 2013 8:07 am
Location: France
Contact:

Re: Redirection of a process output

Post by bertolino »

PB wrote: Mon Apr 12, 2021 3:16 pm I did not try but I think you can call wxExecute() with "cmd /c ffprobe... > output.txt" as the command and it should work? Is the console really still shown even when using wxEXEC_HIDE_CONSOLE ?
Hi PB,
Thank you very much for your answer. Actually, what you suggest works pretty well for a "standard" command redirection (such as cmd /c dir > output.txt) but in my case (with ffprobe, I didn't check yet with another exe) it creates the output file but the file remains empty.

Kind regards,

Pascal
bertolino
Experienced Solver
Experienced Solver
Posts: 77
Joined: Wed Aug 14, 2013 8:07 am
Location: France
Contact:

Re: Redirection of a process output

Post by bertolino »

doublemax wrote: Mon Apr 12, 2021 4:34 pm
But the thing is that wxExecute doesn't handle redirection
Really? What about wxProcess::Redirect(), wxProcess::GetInputStream(), wxProcess::GetOutputStream() etc?

You need to subclass wxProcess, create an instance of it and pass it to wxExecute. Check the "exec" sample, look for occurrences of "MyPipedProcess".
Hi Doublemax,

Thank you for your valuable answer. I already took a look at the exec sample but I surely was to fast and it seemed a bit disconnected to what I was looking for. Your suggestion makes me feel more confident so I I'm going to dig into this point. It seems that it's the only way to achieve what I want to do. Many thanks.
Best regards,

Pascal
bertolino
Experienced Solver
Experienced Solver
Posts: 77
Joined: Wed Aug 14, 2013 8:07 am
Location: France
Contact:

Re: Redirection of a process output

Post by bertolino »

ONEEYEMAN wrote: Mon Apr 12, 2021 3:17 pm Hi,
wxLogXXX?

Thank you.
Hi OneEyeMan!

Though your answer is a bit sibylline, I appreciate that you took time to help :D
Kind regards,

Pascal
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: Redirection of a process output

Post by PB »

bertolino wrote: Mon Apr 12, 2021 7:48 pm Actually, what you suggest works pretty well for a "standard" command redirection (such as cmd /c dir > output.txt) but in my case (with ffprobe, I didn't check yet with another exe) it creates the output file but the file remains empty.
This is funny because when I call from the command line (Win 10, cmd.exe)

Code: Select all

ffprobe 3d_ocean_1590675653.mov > output.txt
empty file output.txt is created and all the output still goes to the console. ffprobe is

Code: Select all

ffprobe version 4.4-full_build-www.gyan.dev
However, when I run

Code: Select all

ffprobe 3d_ocean_1590675653.mov 2> output.txt
the output is properly stored in the file, which indicates that ffprobe uses stderr instead of stdout for its information output?!

However, I am not familiar with ffprobe, so it may be different for kind of outputs...

EDIT
Running

Code: Select all

ffprobe -show_frames 3d_ocean_1590675653.mov 1> frames.txt 2> info.txt
from the command line actually stores the frames in frames.txt and the information in info.txt

I could achieve the same with the exec sample, where in Exec / Execution flags I turned on "Always hide console" and in Exec / Sync Execution entered

Code: Select all

cmd /c ffprobe -show_frames 3d_ocean_1590675653.mov 1> frames.txt 2> info.txt
But you may follow doublemaxe's advice anyway and look into wxProcess which could give you more control.
bertolino
Experienced Solver
Experienced Solver
Posts: 77
Joined: Wed Aug 14, 2013 8:07 am
Location: France
Contact:

Re: Redirection of a process output

Post by bertolino »

Hi PB,

Many thanks for your time and these interesting informations. It really helps me to understand what happens.
Best regards,

Pascal
Post Reply