Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Writing to standard input of a C# based QProcess



  • Re: Writing to the standard input of a process

    In the previous topic, the problem kind of went unsolved. Writing to Standard input with a C++ based QProcess actually works fine [by appending \n]; however, does not do the same for a C# one. Since apparently there's a slight difference "on how the C# runtime uses stdin/stdout", how can I remedy that?

    Note that: I am using a QProcess of powershell, and powershell in turn is executing the C# exe and I cannot change this.



  • @mhmdkanj
    If you test your code outside of Qt via

    echo test | C#-program
    

    how does it behave?



  • @JonB I think it behaves normally outside.
    So If I execute it in a shell, it goes like:
    Enter a string - test You entered 'test'
    Using the echo and piping it, I get:
    Enter a string - You entered 'test'



  • @mhmdkanj
    Unfortunately that probably comes because the output is flushed because the echo process comes to an end.

    What I really need you to test would be like this under Linux shell:

    (echo test ; sleep 10) | C#-program
    

    We would be looking to see whether the echoed line comes out before or after the 10 second sleep. If it's after you are in trouble :(

    You could try: create a temp.bat file containing:

    @echo off
    echo Test
    pause
    

    Now in Command Prompt run temp | more. See how we do get the Test output before pressing a key?

    Then try temp | C#-program. How does that behave?

    In any case, if it is the case that C# output is buffered (or even that it is not reading the input) then you have a problem at the C# side. Is that code under your control or third-party?



  • @JonB I should have probably mentioned that I'm trying all this on Windows. Nevertheless I tried this : (echo test ; sleep 10) | C#-program in a gitbash shell and it displayed Enter a string - You entered 'test' and then waited 10 seconds to finish the program.

    Trying the temp | more would also display Test then pause the shell.

    Trying the temp | C# displays Enter a string - You entered 'Test' and then pauses.

    The thing is is that in theory I do not have control over the C# program. So I want the QProcess with my functionality to take in any exe file and be able to write to standard in and read from standard out. Since the simple C# program I tried normally works in a shell, I want it to work through Qt as well and be able to write data to it from there. doing that to a C++ exe is fine though.

    Also note that the QProcess starts a PowerShell process and Powershell executes the C# program. This is the way I am to implement this [due to set design reasons]



  • @mhmdkanj said in Writing to standard input of a C# based QProcess:

    Trying the temp | C# displays Enter a string - You entered 'Test' and then pauses.

    Assuming it does not pause for 10 seconds before displaying the message, then I don't know what is different from the situation compared to writing to/reading from it via QProcess in your Qt program....


Log in to reply