On Wednesday 25 September 2024 06:17:11 GMT-7 christ...@cullmann.io wrote:
> Hi,
> 
> I want to ensure only the standard handles are inherited.

Hello Cristoph

> For Unix this seems to work fine with:
> 
>      QProcess::UnixProcessParameters params;
>      params.flags = QProcess::UnixProcessFlag::CloseFileDescriptors;
>      params.lowestFileDescriptorToClose = 0;
>      m_process.setUnixProcessParameters(params);
>      m_process.start(....

lowestFileDescriptorToClose defaults to 0, so you don't have to set it. If 
you're going to set, I expect you to set it to something higher than 
STDERR_FILENO + 1 (which is the minimum), for whatever your need is.

> For Windows I tried something like:
> 
> https://devblogs.microsoft.com/oldnewthing/20111216-00/?p=8873
> 
> via: (the UR_ENSURE stuff just checks if return value is sane)
> 
>      STARTUPINFOEX info;
>      ZeroMemory(&info, sizeof(info));
> 
> m_process.setCreateProcessArgumentsModifier([&info](QProcess::CreateProcessA
> rguments *args) {
...
>          args->startupInfo = &info.StartupInfo;

You don't need to pass your own startupInfo here. At least you made sure it's 
valid around the CreateProcess call, so no dangling pointer, which was my first 
worry. But args should have a valid startupInfo pointer you can modify.

>      });
>      m_process.start(....
> 
> But with that I end up without any valid handles that can be used to get
> output from the QProcess m_process.
> 
> Any pointers how to do that correctly would be very welcome. (or if I
> just missed to used the proper Qt API for that)

Since you want no handles but the standard three, would setting 
  args->inheritHandles = false
suffice?


-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Principal Engineer - Intel DCAI Platform & System Engineering

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest

Reply via email to