QProcess STDIN with show console
-
Hi Every body.
I want to create a process under QProcess with console show and acccess STDIN and STDOUT streams.my code:
@QProcess *p1 = new QProcess(this);
p1->start("cmd.exe");@if I want to show console I must use startDeatached() function, but by using this, I lost my STDIN/OUT access in my program.
if I want to have access these, I dont have my console show!!!???
help me tanx. -
The common misconception is that cmd.exe is the little black window. It's not. It's a windowless program that reads input stream and writes to output stream.
When you start the process detached the cmd.exe program is not tied to your app in any way. OS sees that a console app is started and, since nothing claims the input/output buffers of it, the OS creates a window through which it can communicate the streams to the user.
When you start a process (not detached) YOUR app is the "window". It's your responsibility to write to the input stream, read any output and present the data to the user. If you want to, you can open a widget with a textedit and color it to look like the windows command prompt. You can also create a system console window and redirect the streams, but you can't have the default detached program forward the streams to your app. It doesn't have such functionality and the cmd.exe knows nothing about either your app or the little black window the OS decided to run it in so it won't help you either.
If you want the little black window provided by the OS then it's a platform dependant thing. On Windows you can use "AllocConsole":http://msdn.microsoft.com/en-us/library/ms681944.aspx and "FreeConsole":http://msdn.microsoft.com/en-us/library/ms683150.aspx, but remember that you will have to redirect any streams you handle to it.
-
Hi man.
I am a c++ coder for last 10 years and I know what you say clearly. but my employer needs console application exactly. I know that I can use CreatePipe() Windows API to do some thing like this and I did it but it makes my code messy, and I don't what to do this.
By the way, Thanks for your suggestion.