Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Pipe from GUI app to console process

Pipe from GUI app to console process

Scheduled Pinned Locked Moved C / C++ / MFC
helpsysadminsecurity
5 Posts 3 Posters 0 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.
  • R Offline
    R Offline
    RickyC
    wrote on last edited by
    #1

    Hello everybody! I've been working for some hours in a project of a GUI app that runs a console app (ssh) in background. Well, I've been using many examples of code from here (codeproject) and from the internet, but I had aways stoped at the same error. Maybe someone can give me some help... here is what happens: I create the pipes and begin the execution of the program... everything goes fine, the ssh program ask for the password, and then I use WriteFile to send it the password. >Crash!< It continues the execution and do not even try to validate the password :sigh: I'll put some code here:

    //creating pipes
    if(!CreatePipe(&hChildStdoutRd, &hChildStdoutWr, &secattr, 0))
    AfxMessageBox("Error in pipe Out");

    SetHandleInformation(hChildStdoutRd, HANDLE_FLAG_INHERIT, 0);

    if(!CreatePipe(&hChildStdinRd, &hChildStdinWr, &secattr, 0))
    AfxMessageBox("Error in pipe In");

    SetHandleInformation(hChildStdinWr, HANDLE_FLAG_INHERIT, 0);

    /////////////////////////////////////////////////////////////
    // In another thread, I started the app. The pipes stay in a object that is
    // passed through parameter to the thread execution.
    STARTUPINFO sInfo;
    ZeroMemory(&sInfo,sizeof(sInfo));
    PROCESS_INFORMATION pInfo;
    ZeroMemory(&pInfo,sizeof(pInfo));
    sInfo.cb=sizeof(sInfo);
    sInfo.dwFlags |= STARTF_USESTDHANDLES;
    sInfo.hStdInput = cssh->hChildStdinRd;
    sInfo.hStdOutput = cssh->hChildStdoutWr;
    sInfo.hStdError = cssh->hChildStdoutWr;

    //In the same thread, I read the first line of execution...
    CloseHandle(csftp->hChildStdoutWr);

    for( ;; ) {
    if(!ReadFile(csftp->hChildStdoutRd, buf, 100, &dwRead, NULL) || dwRead == 0)
    break;

    buf[dwRead] = '\0';
    strAux = buf;
    cssh->ShowText(strAux);
    }

    // The password is typed in a Edit (for test porpouse only), and a try this code:
    strcpy(strPass, szBuf);

    if(!WriteFile(hChildStdinWr, szBuf, strPass.GetLength() ,&dwWritten, NULL))
    AfxMessageBox("Error in hChildStdinWr");

    if(!CloseHandle(hChildStdinWr))
    AfxMessageBox("Error in hChildStdinWr");

    After execute the code above, the ssh app runs all the authentication with failure user@host's password: user@host's password: user@host's password: user@host's password: user@host's password: Using username "user". Access denied Access denied Access denied Access denied Access denied Fatal: Server sent disconnect message type 2 (SSH_DISCONNECT_PROTOCOL_ERROR): "Too many authentication failures for user" Any help, is welcome :) chee

    D I 2 Replies Last reply
    0
    • R RickyC

      Hello everybody! I've been working for some hours in a project of a GUI app that runs a console app (ssh) in background. Well, I've been using many examples of code from here (codeproject) and from the internet, but I had aways stoped at the same error. Maybe someone can give me some help... here is what happens: I create the pipes and begin the execution of the program... everything goes fine, the ssh program ask for the password, and then I use WriteFile to send it the password. >Crash!< It continues the execution and do not even try to validate the password :sigh: I'll put some code here:

      //creating pipes
      if(!CreatePipe(&hChildStdoutRd, &hChildStdoutWr, &secattr, 0))
      AfxMessageBox("Error in pipe Out");

      SetHandleInformation(hChildStdoutRd, HANDLE_FLAG_INHERIT, 0);

      if(!CreatePipe(&hChildStdinRd, &hChildStdinWr, &secattr, 0))
      AfxMessageBox("Error in pipe In");

      SetHandleInformation(hChildStdinWr, HANDLE_FLAG_INHERIT, 0);

      /////////////////////////////////////////////////////////////
      // In another thread, I started the app. The pipes stay in a object that is
      // passed through parameter to the thread execution.
      STARTUPINFO sInfo;
      ZeroMemory(&sInfo,sizeof(sInfo));
      PROCESS_INFORMATION pInfo;
      ZeroMemory(&pInfo,sizeof(pInfo));
      sInfo.cb=sizeof(sInfo);
      sInfo.dwFlags |= STARTF_USESTDHANDLES;
      sInfo.hStdInput = cssh->hChildStdinRd;
      sInfo.hStdOutput = cssh->hChildStdoutWr;
      sInfo.hStdError = cssh->hChildStdoutWr;

      //In the same thread, I read the first line of execution...
      CloseHandle(csftp->hChildStdoutWr);

      for( ;; ) {
      if(!ReadFile(csftp->hChildStdoutRd, buf, 100, &dwRead, NULL) || dwRead == 0)
      break;

      buf[dwRead] = '\0';
      strAux = buf;
      cssh->ShowText(strAux);
      }

      // The password is typed in a Edit (for test porpouse only), and a try this code:
      strcpy(strPass, szBuf);

      if(!WriteFile(hChildStdinWr, szBuf, strPass.GetLength() ,&dwWritten, NULL))
      AfxMessageBox("Error in hChildStdinWr");

      if(!CloseHandle(hChildStdinWr))
      AfxMessageBox("Error in hChildStdinWr");

      After execute the code above, the ssh app runs all the authentication with failure user@host's password: user@host's password: user@host's password: user@host's password: user@host's password: Using username "user". Access denied Access denied Access denied Access denied Access denied Fatal: Server sent disconnect message type 2 (SSH_DISCONNECT_PROTOCOL_ERROR): "Too many authentication failures for user" Any help, is welcome :) chee

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Have you seen these two articles: http://support.microsoft.com/default.aspx?scid=kb;en-us;190351[^] http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/creating_a_child_process_with_redirected_input_and_output.asp[^]


      "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

      "There is no death, only a change of worlds." - Native American Proverb

      R 2 Replies Last reply
      0
      • D David Crow

        Have you seen these two articles: http://support.microsoft.com/default.aspx?scid=kb;en-us;190351[^] http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/creating_a_child_process_with_redirected_input_and_output.asp[^]


        "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

        "There is no death, only a change of worlds." - Native American Proverb

        R Offline
        R Offline
        RickyC
        wrote on last edited by
        #3

        Hi David, thanks for your quick reply. Yes, I read those articles. But I still have problems to 'adapt' to a GUI app... they all implement console applications. thanks anyway -- modified at 9:23 Tuesday 11th April, 2006

        1 Reply Last reply
        0
        • D David Crow

          Have you seen these two articles: http://support.microsoft.com/default.aspx?scid=kb;en-us;190351[^] http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/creating_a_child_process_with_redirected_input_and_output.asp[^]


          "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

          "There is no death, only a change of worlds." - Native American Proverb

          R Offline
          R Offline
          RickyC
          wrote on last edited by
          #4

          Hi Dadiv, All. I found the problem.

          if(!CloseHandle(hChildStdinWr))
          AfxMessageBox("Erro ao fechar o handle hChildStdinWr");

          This handle, must not be close. Thanks all for the atention, Regards!:)

          1 Reply Last reply
          0
          • R RickyC

            Hello everybody! I've been working for some hours in a project of a GUI app that runs a console app (ssh) in background. Well, I've been using many examples of code from here (codeproject) and from the internet, but I had aways stoped at the same error. Maybe someone can give me some help... here is what happens: I create the pipes and begin the execution of the program... everything goes fine, the ssh program ask for the password, and then I use WriteFile to send it the password. >Crash!< It continues the execution and do not even try to validate the password :sigh: I'll put some code here:

            //creating pipes
            if(!CreatePipe(&hChildStdoutRd, &hChildStdoutWr, &secattr, 0))
            AfxMessageBox("Error in pipe Out");

            SetHandleInformation(hChildStdoutRd, HANDLE_FLAG_INHERIT, 0);

            if(!CreatePipe(&hChildStdinRd, &hChildStdinWr, &secattr, 0))
            AfxMessageBox("Error in pipe In");

            SetHandleInformation(hChildStdinWr, HANDLE_FLAG_INHERIT, 0);

            /////////////////////////////////////////////////////////////
            // In another thread, I started the app. The pipes stay in a object that is
            // passed through parameter to the thread execution.
            STARTUPINFO sInfo;
            ZeroMemory(&sInfo,sizeof(sInfo));
            PROCESS_INFORMATION pInfo;
            ZeroMemory(&pInfo,sizeof(pInfo));
            sInfo.cb=sizeof(sInfo);
            sInfo.dwFlags |= STARTF_USESTDHANDLES;
            sInfo.hStdInput = cssh->hChildStdinRd;
            sInfo.hStdOutput = cssh->hChildStdoutWr;
            sInfo.hStdError = cssh->hChildStdoutWr;

            //In the same thread, I read the first line of execution...
            CloseHandle(csftp->hChildStdoutWr);

            for( ;; ) {
            if(!ReadFile(csftp->hChildStdoutRd, buf, 100, &dwRead, NULL) || dwRead == 0)
            break;

            buf[dwRead] = '\0';
            strAux = buf;
            cssh->ShowText(strAux);
            }

            // The password is typed in a Edit (for test porpouse only), and a try this code:
            strcpy(strPass, szBuf);

            if(!WriteFile(hChildStdinWr, szBuf, strPass.GetLength() ,&dwWritten, NULL))
            AfxMessageBox("Error in hChildStdinWr");

            if(!CloseHandle(hChildStdinWr))
            AfxMessageBox("Error in hChildStdinWr");

            After execute the code above, the ssh app runs all the authentication with failure user@host's password: user@host's password: user@host's password: user@host's password: user@host's password: Using username "user". Access denied Access denied Access denied Access denied Access denied Fatal: Server sent disconnect message type 2 (SSH_DISCONNECT_PROTOCOL_ERROR): "Too many authentication failures for user" Any help, is welcome :) chee

            I Offline
            I Offline
            includeh10
            wrote on last edited by
            #5

            1)upload ur code somewhere, someone may download and test it for u. 2)u do need to study a sample carefully. at least, i don't think code like this meaningful: sInfo.hStdInput = cssh->hChildStdinRd; before u call CreatePipe() and CreateProcess()


            A special image tool for C++ programmers, don't miss it! The world unique Software Label Maker is here for you and me ... A nice hyper tool for optimizing your MS html-help contents.


            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups