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. QProcess STDIN with show console

QProcess STDIN with show console

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.0k Views 1 Watching
  • 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.
  • N Offline
    N Offline
    NasserAll
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • N Offline
        N Offline
        NasserAll
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0

        • Login

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