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
Unfortunately that probably comes because the output is flushed because theecho
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 theTest
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 displayedEnter a string - You entered 'test'
and then waited 10 seconds to finish the program.Trying the
temp | more
would also displayTest
then pause the shell.Trying the
temp | C#
displaysEnter 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....