[Interest] QProcess unbuffered

Scott Bloom scott at towel42.com
Wed Mar 8 20:57:34 CET 2023


From: Björn Schäpers <qt-maillist at hazardy.de> 
Sent: Wednesday, March 8, 2023 11:45 AM
To: Scott Bloom <scott at towel42.com>; interest at qt-project.org
Subject: Re: [Interest] QProcess unbuffered

Am 08.03.2023 um 03:18 schrieb Scott Bloom:
> I really want to thank Björn
>
> With his starting point, I was able to tweak his changes, and seem to have it working 😊 I have more testing to do. But it was actually pretty straight forward.
>
> * I use VS (2022) so the packing was different
> 	__attribute__((packed)) became  __pragma( pack( push, 1 ) ) struct 
> HackedHandlePasser
> * The handles are 64 bit in the existing Startup Info, so I kept them as such, which changed the definition of HANDLE32
>           using HANDLE32 = std::int32_t; was removed, and the standard 
> HANDLE defined in windows.h was used
> * The static assert was updated to reflect this
> * I copy all 3 handles from the existing startupinfo
>         std::memcpy(&handles.Handles[0], &invalid, 4);
>         std::memcpy(&handles.Handles[1], &pipe.Write, 4);
>         std::memcpy(&handles.Handles[2], &pipe.Write, 4);
>
>         became
>
>          std::memcpy( &handles.Handles[ 0 ], &args->startupInfo->hStdInput, sizeof( HANDLE ) );
>          std::memcpy( &handles.Handles[ 1 ], &args->startupInfo->hStdOutput, sizeof( HANDLE ) );
>          std::memcpy( &handles.Handles[ 2 ], 
> &args->startupInfo->hStdError, sizeof( HANDLE ) );
>
> Then I wrapped this into a function that returns a QProcess::QCreateProcessArgumentModifier.
>
> And finally in my process, I set the modifier using process-> 
> setCreateProcessArgumentsModifier( func );
>
> You can find the code
> https://github.com/towel42-com/SABUtils/blob/trunk/ForceUnbufferedProc
> essModifier.h
> and
> https://github.com/towel42-com/SABUtils/blob/trunk/ForceUnbufferedProc
> essModifier.cpp
>
> and its usage at
> https://github.com/towel42-com/MediaManager/blob/trunk/Models/DirModel
> .cpp
>
> Thanks again.
> Scott
>
>
Happy for you.
I assume you don't use write() to the process, right? Because I think if you want to do that, you'd have to set FOPEN for the hStdInput handle.

===========

I don’t touch it, I simply copy the pointer to the new handles from the old Qt handles.


More information about the Interest mailing list