PDA

View Full Version : How to input argument at the middle of running process using QProcess



ashukla
18th May 2009, 07:51
I want to read local system's particular unread mail using mail command. Suppose
I want to read mail no. 5 using mail command. The Syntax is


mail
Mail version 8.1 6/6/93. Type ? for help.
"/var/spool/mail/root": 12 messages 12 unread
>U 1 MAILER-DAEMON@localh Fri May 15 15:53 73/2415 "Returned mail: see tr"
U 2 root@localhost.local Fri May 15 15:54 19/747 "psad-alert"
U 3 root@localhost.local Fri May 15 16:00 21/721 "psad-alert"
U 4 root@localhost.local Fri May 15 17:40 18/682 "psad-alert"
U 5 MAILER-DAEMON@localh Mon May 18 09:16 68/2333 "Warning: could not se"
U 6 MAILER-DAEMON@localh Mon May 18 09:16 70/2341 "Warning: could not se"
U 7 MAILER-DAEMON@localh Mon May 18 09:16 69/2350 "Warning: could not se"
U 8 MAILER-DAEMON@localh Mon May 18 09:16 69/2389 "Warning: could not se"
U 9 MAILER-DAEMON@localh Mon May 18 09:16 68/2381 "Warning: could not se"
U 10 MAILER-DAEMON@localh Mon May 18 09:16 67/2431 "Warning: could not se"
U 11 MAILER-DAEMON@localh Mon May 18 09:16 66/2322 "Warning: could not se"
U 12 MAILER-DAEMON@localh Mon May 18 09:16 68/2338 "Warning: could not se"
&
then enter 5 for reading 5th mail.

My problem begins here to read this mail via QProcess. How to pass 5 no after issuing the mail command when mail list with no. displays...


procMsg =new QProcess(this);
QStringList arguments;

arguments << "\n" << msgKey << "\n";

procMsg->start("mail");
QByteArray result=procMsg->readAllStandardOutput ();

QTextStream stream(&result);
while (!stream.atEnd())
{
line += stream.readLine();
}



U 12 MAILER-DAEMON@localh Mon May 18 09:16 68/2338 "Warning: could not se"
& 5
Message 5:
From MAILER-DAEMON@localhost.localdomain Mon May 18 09:16:20 2009
Date: Mon, 18 May 2009 09:16:20 +0530
From: Mail Delivery Subsystem <MAILER-DAEMON@localhost.localdomain>
To: root@localhost.localdomain
MIME-Version: 1.0
Content-Type: multipart/report; report-type=delivery-status;
boundary="n4I3kFwx002482.1242618380/localhost.localdomain"
Subject: Warning: could not send message for past 4 hours
Auto-Submitted: auto-generated (warning-timeout)

This is a MIME-encapsulated message

--n4I3kFwx002482.1242618380/localhost.localdomain

**********************************************
** THIS IS A WARNING MESSAGE ONLY **
** YOU DO NOT NEED TO RESEND YOUR MESSAGE **
**********************************************

The original message was received at Fri, 15 May 2009 15:43:18 +0530
from root@localhost

for showing the content of conventional mail system under LINUX.

caduel
18th May 2009, 09:49
QProcess inherits from QIODevice which you can use to write data to your process' stdin.

HTH