Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Writing to standard input of a C# based QProcess
Forum Update on Monday, May 27th 2025

Writing to standard input of a C# based QProcess

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 572 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mhmdkanj
    wrote on 23 Sept 2020, 09:40 last edited by mhmdkanj
    #1

    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.

    J 1 Reply Last reply 23 Sept 2020, 09:54
    0
    • M mhmdkanj
      23 Sept 2020, 09:40

      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.

      J Offline
      J Offline
      JonB
      wrote on 23 Sept 2020, 09:54 last edited by
      #2

      @mhmdkanj
      If you test your code outside of Qt via

      echo test | C#-program
      

      how does it behave?

      M 1 Reply Last reply 23 Sept 2020, 10:18
      0
      • J JonB
        23 Sept 2020, 09:54

        @mhmdkanj
        If you test your code outside of Qt via

        echo test | C#-program
        

        how does it behave?

        M Offline
        M Offline
        mhmdkanj
        wrote on 23 Sept 2020, 10:18 last edited by
        #3

        @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'

        J 1 Reply Last reply 23 Sept 2020, 10:30
        0
        • M mhmdkanj
          23 Sept 2020, 10:18

          @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'

          J Offline
          J Offline
          JonB
          wrote on 23 Sept 2020, 10:30 last edited by
          #4

          @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?

          M 1 Reply Last reply 23 Sept 2020, 10:46
          0
          • J JonB
            23 Sept 2020, 10:30

            @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?

            M Offline
            M Offline
            mhmdkanj
            wrote on 23 Sept 2020, 10:46 last edited by mhmdkanj
            #5

            @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]

            J 1 Reply Last reply 23 Sept 2020, 11:09
            0
            • M mhmdkanj
              23 Sept 2020, 10:46

              @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]

              J Offline
              J Offline
              JonB
              wrote on 23 Sept 2020, 11:09 last edited by
              #6

              @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....

              1 Reply Last reply
              0

              1/6

              23 Sept 2020, 09:40

              • Login

              • Login or register to search.
              1 out of 6
              • First post
                1/6
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved