ConPty in CMake/Qt project - pipes don't work #587

Closed
opened 2026-01-30 21:56:13 +00:00 by claunia · 4 comments
Owner

Originally created by @kafeg on GitHub (Mar 17, 2019).

Hello!

I try to create Qt binding for ConPty and I use CMake as build-system for my project. And my problem is: ConPty doesn't write its own output to a pipe, it just write all into stdout of my main process. As if a child and my parent stdout channels merged. I try to create a realization with named and anonymous pipes (from EchoCon example), but it both fail =(

I don't know what I do wrong - all my code are the same of EchoCon example, but project not work as expected.

Information about my system:

  • Microsoft Windows [Version 10.0.18342.8]
  • Windows SDK Version 10.0.18346.0

I build my project with cmake in Qt Creator with MSVC. I double checked, cmake use latest available SDK. Also original EchoCon sample is working fine on my system, but copied from it code built with cmake - not =(

You can find not working code here: https://github.com/kafeg/ptyqt/blob/master/core/conptyanonymouspipeprocess.cpp

Originally created by @kafeg on GitHub (Mar 17, 2019). Hello! I try to create Qt binding for ConPty and I use CMake as build-system for my project. And my problem is: ConPty doesn't write its own output to a pipe, it just write all into stdout of my main process. As if a child and my parent stdout channels merged. I try to create a realization with named and anonymous pipes (from EchoCon example), but it both fail =( I don't know what I do wrong - all my code are the same of EchoCon example, but project not work as expected. Information about my system: - Microsoft Windows [Version 10.0.18342.8] - Windows SDK Version 10.0.18346.0 I build my project with cmake in Qt Creator with MSVC. I double checked, cmake use latest available SDK. Also original EchoCon sample is working fine on my system, but copied from it code built with cmake - not =( You can find not working code here: https://github.com/kafeg/ptyqt/blob/master/core/conptyanonymouspipeprocess.cpp
Author
Owner

@DHowett-MSFT commented on GitHub (Mar 17, 2019):

Hey @kafeg,
It looks like you're reading from the input pipe and writing to the output pipe. Try switching those around and seeing what ends up in your read buffer.

@DHowett-MSFT commented on GitHub (Mar 17, 2019): Hey @kafeg, It looks like you're [reading from the input pipe](https://github.com/kafeg/ptyqt/blob/master/core/conptyanonymouspipeprocess.cpp#L190) and [writing to the output pipe](https://github.com/kafeg/ptyqt/blob/master/core/conptyanonymouspipeprocess.cpp#L301). Try switching those around and seeing what ends up in your read buffer.
Author
Owner

@kafeg commented on GitHub (Mar 18, 2019):

@DHowett-MSFT, sorry, but are you sure?

In original example are the same pipe used to read from Pty:

//  Create the Pseudo Console and pipes to it
HANDLE hPipeIn{ INVALID_HANDLE_VALUE };
HANDLE hPipeOut{ INVALID_HANDLE_VALUE };
hr = CreatePseudoConsoleAndPipes(&hPC, &hPipeIn, &hPipeOut);
...

// Here used 'hPipeIn' as parameter for PipeListener
HANDLE hPipeListenerThread{ reinterpret_cast<HANDLE>(_beginthread(PipeListener, 0, hPipeIn)) };
...

//and PipeListener:
void __cdecl PipeListener(LPVOID pipe)
{
    HANDLE hPipe{ pipe };
    ...
    fRead = ReadFile(hPipe, szBuffer, BUFF_SIZE, &dwBytesRead, NULL);
    ...
}

And this combination works.

@kafeg commented on GitHub (Mar 18, 2019): @DHowett-MSFT, sorry, but are you sure? In original example are the same pipe used to read from Pty: ```cpp // Create the Pseudo Console and pipes to it HANDLE hPipeIn{ INVALID_HANDLE_VALUE }; HANDLE hPipeOut{ INVALID_HANDLE_VALUE }; hr = CreatePseudoConsoleAndPipes(&hPC, &hPipeIn, &hPipeOut); ... // Here used 'hPipeIn' as parameter for PipeListener HANDLE hPipeListenerThread{ reinterpret_cast<HANDLE>(_beginthread(PipeListener, 0, hPipeIn)) }; ... //and PipeListener: void __cdecl PipeListener(LPVOID pipe) { HANDLE hPipe{ pipe }; ... fRead = ReadFile(hPipe, szBuffer, BUFF_SIZE, &dwBytesRead, NULL); ... } ``` And this combination works.
Author
Owner

@kafeg commented on GitHub (Mar 18, 2019):

So, I try switch pipes, but it still not work =(

@kafeg commented on GitHub (Mar 18, 2019): So, I try switch pipes, but it still not work =(
Author
Owner

@kafeg commented on GitHub (Mar 19, 2019):

All works fine, an important part is to run the application from the existing console window.

@kafeg commented on GitHub (Mar 19, 2019): All works fine, an important part is to run the application from the existing console window.
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#587