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. [SOLVED]QProcess run external cmd.exe with interactive input

[SOLVED]QProcess run external cmd.exe with interactive input

Scheduled Pinned Locked Moved General and Desktop
qprocess
7 Posts 3 Posters 6.8k 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.
  • S Offline
    S Offline
    saeedhardan
    wrote on 5 Apr 2015, 09:05 last edited by saeedhardan 4 Jun 2015, 07:41
    #1

    Hi,
    I want to run and external *.exe program , that can ask for input like (y/n)....
    How can i run this program from qt and be able to enter the input ?
    i know about readstandarouput() and displaying it , but i need to know how to Input stuff not read .

        QStringList input_list = QStringList() << QString("-be") << QString("-pw") << QString(session->get_ftp_password())
                                << QString(QString(session->get_ftp_username())+"@"+QString(session->get_ftp_ip()))
                                << QString("-b") << QString("cmd.in");
        process->start( "tools/psftp.exe",input_list,QIODevice::ReadOnly | QIODevice::Text);
    
        if(!process->waitForFinished()){
            delete process;
            return false;
        }else{
        }
        delete process;
    
    here all i can do is run the process and get its output , i have no way to insert input .
    1 Reply Last reply
    0
    • M Offline
      M Offline
      mking
      wrote on 5 Apr 2015, 18:26 last edited by
      #2

      Sorry to say, but I don't think you can. The process isn't connected to anything that you can write to.

      The only way I know to make this work is to provide all input via command line arguments and switches, which means the program itself must support that functionality.

      Assuming this is the same psftp that you are using, it looks like providing the --batch command may tell it to not ask you anything.
      http://the.earth.li/~sgtatham/putty/0.60/htmldoc/Chapter6.html#psftp-usage-options-batch

      If that's not the same psftp (or a different version, etc.), the same advice applies. Look up the program, determine what parameters you can use to disable interactivity and provide all necessary info on the command line.

      Hope that helps!

      1 Reply Last reply
      0
      • C Offline
        C Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on 5 Apr 2015, 18:40 last edited by
        #3

        QProcess inherits QIODevice. You can use any of its write methods to write to the input stream of the process.

        S 1 Reply Last reply 6 Apr 2015, 07:40
        0
        • S Offline
          S Offline
          saeedhardan
          wrote on 6 Apr 2015, 07:16 last edited by
          #4

          it is the same psftp , but the problem with --batch is when connecting to a server for the first time you need to accept the servers new key , and with --batch it doesn't ask you , by default it terminates the connection.

          1 Reply Last reply
          0
          • C Chris Kawa
            5 Apr 2015, 18:40

            QProcess inherits QIODevice. You can use any of its write methods to write to the input stream of the process.

            S Offline
            S Offline
            saeedhardan
            wrote on 6 Apr 2015, 07:40 last edited by
            #5

            @Chris-Kawa thanks , i just wrote process->write("y\n") ;
            i hope there will be a better "solution" , because right now i don't know what the process asks and just give it y to continue .

            1 Reply Last reply
            0
            • C Offline
              C Offline
              Chris Kawa
              Lifetime Qt Champion
              wrote on 6 Apr 2015, 08:41 last edited by
              #6

              Lets hope it doesn't ask you to format the hard drive ;)

              No, you should definitely not answer "y" without knowing the question. Connect to readyReadStandardOutput signal of the process. In the halndler read standard output, parse it and decide what to answer if needed.

              S 1 Reply Last reply 6 Apr 2015, 15:48
              0
              • C Chris Kawa
                6 Apr 2015, 08:41

                Lets hope it doesn't ask you to format the hard drive ;)

                No, you should definitely not answer "y" without knowing the question. Connect to readyReadStandardOutput signal of the process. In the halndler read standard output, parse it and decide what to answer if needed.

                S Offline
                S Offline
                saeedhardan
                wrote on 6 Apr 2015, 15:48 last edited by
                #7

                @Chris-Kawa yeah thanks a lot thats what i did after your answer :D .

                1 Reply Last reply
                0

                6/7

                6 Apr 2015, 08:41

                • Login

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