[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Interacting with KProcess
From:       "YM Chen" <fusion82 () gmail ! com>
Date:       2008-09-30 12:58:28
Message-ID: 477cca6f0809300558h184ab09en10e189bd93645946 () mail ! gmail ! com
[Download RAW message or body]

Hello,

I am still pretty new to Qt/KDE framework.
I am trying to improve child process handling for ark's plugin
For example, when listing or extracting files from the archive, 7zip
prompts for password.
I have tried the following approach to get the list of files, but does not work.

bool p7zipInterface::list()
{
       m_kprocess = new KProcess;
       *m_kprocess << "7z" << "l" << filename;
       connect(m_kprocess, SIGNAL(
readyReadStandardOutput()), SLOT(processReadyReadStdOut()));
       m_kprocess->start();

       if (!m_kprocess->waitForStarted())
               return false;


       if (!m_kprocess->waitForFinished())
               return false;

       return true;
}


void p7zipInterface::processReadyReadStdOut()
{
       QString readAllData(m_kprocess->readAll());
       QStringList lines = readAllData.split(QRegExp("[\\r\\n]+"),
QString::SkipEmptyParts);
       foreach (QString line, lines){
                if (line.contains("Enter password"))
               {
                       m_kprocess->write("secretPassword\n"); // write
the password
               }
               else
                       / * parse for other output lines */
       }
}


After the process is started, I received the signal and then could
start reading the stdout.
When it stopped to prompt for password, I would assume that writing
the password to KProcess followed by newline would send the password
to the process and then receive another signal for additional data to
receive, but I don't get any data and it just crashes.

Is there any way that allows me to interact with the child process's
IO streams interactively... like  reply  the prompts from the child
process such as password, file over-write confirmation etc?

Any help would be really appreciated.

Thanks,
YewMing Chen
 
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic