Results 1 to 6 of 6

Thread: Execute window command line-by-line using QProcess

  1. #1
    Join Date
    Jul 2013
    Posts
    9
    Thanks
    5

    Default Execute window command line-by-line using QProcess

    I want to make an application which can download email content by using command line. For example with gmail we can get email by execute following command in Command Promt:
    (note you have to install openssl first)

    Qt Code:
    1. >opensslOpenSSL>s_client -connect pop.gmail.com:995
    2. Loading 'screen' into random state - done
    3. CONNECTED(00000168)
    4. depth=1 C = US, O = Google Inc, CN = Google Internet Authority
    5. verify error:num=20:unable to get local issuer certificate
    6. verify return:0
    7. ---
    8. Certificate chain
    9. 0 s:/C=US/ST=California/L=Mountain View/O=Google Inc/CN=pop.gmail.com
    10. i:/C=US/O=Google Inc/CN=Google Internet Authority
    11. 1 s:/C=US/O=Google Inc/CN=Google Internet Authority
    12. i:/C=US/O=Equifax/OU=Equifax Secure Certificate Authority
    13. ---
    14. Server certificate
    15. -----BEGIN CERTIFICATE-----
    16. MIIDfjCCAuegAwIBAgIKVExoXgABAACEMTANBgkqhkiG9w0BAQUFADBGMQswCQYD
    17. VQQGEwJVUzETMBEGA1UEChMKR29vZ2xlIEluYzEiMCAGA1UEAxMZR29vZ2xlIElu
    18. dGVybmV0IEF1dGhvcml0eTAeFw0xMzA0MTUwODQ1MjVaFw0xMzEyMzExNTU4NTBa
    19. MGcxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1N
    20. b3VudGFpbiBWaWV3MRMwEQYDVQQKEwpHb29nbGUgSW5jMRYwFAYDVQQDEw1wb3Au
    21. Z21haWwuY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDJcFLd/CvEAEYb
    22. PComwfh/VJnV4I0AbErRIBztla7KdaOL3SN8a2lnKKZSkX9fhIMQ8mwCyZ8iWzLG
    23. aXaWr64uChCH2lQNA6O5B/kcLeBfWV51Fwqiq6aRQxpYY7sUqOP03oABRLtBiFOq
    24. wCCLLbkeEcjLuWzzebFk2HX6L++02wIDAQABo4IBUDCCAUwwHQYDVR0lBBYwFAYI
    25. KwYBBQUHAwEGCCsGAQUFBwMCMB0GA1UdDgQWBBS3kDe0ZShOJvpTHlTbh4fjZtVf
    26. lDAfBgNVHSMEGDAWgBS/wDDr9UMRPme6npH7/Gra42sSJDBbBgNVHR8EVDBSMFCg
    27. TqBMhkpodHRwOi8vd3d3LmdzdGF0aWMuY29tL0dvb2dsZUludGVybmV0QXV0aG9y
    28. aXR5L0dvb2dsZUludGVybmV0QXV0aG9yaXR5LmNybDBmBggrBgEFBQcBAQRaMFgw
    29. VgYIKwYBBQUHMAKGSmh0dHA6Ly93d3cuZ3N0YXRpYy5jb20vR29vZ2xlSW50ZXJu
    30. ZXRBdXRob3JpdHkvR29vZ2xlSW50ZXJuZXRBdXRob3JpdHkuY3J0MAwGA1UdEwEB
    31. /wQCMAAwGAYDVR0RBBEwD4INcG9wLmdtYWlsLmNvbTANBgkqhkiG9w0BAQUFAAOB
    32. gQA8MCOlbZZGyLz5byFAq6eFhNw74ahaKVW3QeskRkPUI7hkr37Kmoaq8PE9Oosk
    33. lewH6mgDjheUb6DJJhNhnmcgkAvLfyq0fdDKceSwpTbV5xjcKp3/0G0lzKSMxB7C
    34. oOzEcClsFNLx6EP4FsJS1ELJRGbop7xQF8Wz/5mr88HjFw==
    35. -----END CERTIFICATE-----
    36. subject=/C=US/ST=California/L=Mountain View/O=Google Inc/CN=pop.gmail.com
    37. issuer=/C=US/O=Google Inc/CN=Google Internet Authority
    38. ---
    39. No client certificate CA names sent
    40. ---
    41. SSL handshake has read 2108 bytes and written 443 bytes
    42. ---
    43. New, TLSv1/SSLv3, Cipher is ECDHE-RSA-RC4-SHA
    44. Server public key is 1024 bit
    45. Secure Renegotiation IS supported
    46. Compression: NONE
    47. Expansion: NONE
    48. SSL-Session:
    49. Protocol : TLSv1.2
    50. Cipher : ECDHE-RSA-RC4-SHA
    51. Session-ID: 8FD510E5074D67B5052E8B68171CD55FC14132282232B0D4A090CBC3248719BA
    52.  
    53. Session-ID-ctx:
    54. Master-Key: 1E0D5DCDD8DB167CCB2C8C3CCDDCE0CF65D41A3D49D113125376801C9706FDAC
    55. FCFBFB32A9A174FFE07AF0939D1BE122
    56. Key-Arg : None
    57. PSK identity: None
    58. PSK identity hint: None
    59. SRP username: None
    60. TLS session ticket lifetime hint: 100800 (seconds)
    61. TLS session ticket:
    62. 0000 - bc 52 af c7 83 85 57 69-f4 c3 11 a5 de 03 b9 ce .R....Wi........
    63. 0010 - c1 c7 5d 39 e3 6a d8 d2-fe 9d 8b 4a 1a 61 33 a8 ..]9.j.....J.a3.
    64. 0020 - 3a dc bd 79 b8 f7 ee 44-39 3d bb 24 1f 7a 6a 18 :..y...D9=.$.zj.
    65. 0030 - 0b b9 b5 99 7b ee 9a 15-3a 64 18 78 22 2e 04 5e ....{...:d.x"..^
    66. 0040 - b3 6a e3 04 6e c3 52 d8-21 00 3d 3b a3 82 7d ca .j..n.R.!.=;..}.
    67. 0050 - e5 3a e9 c6 4f d8 fa 46-77 4e 1c 2e 93 f3 22 81 .:..O..FwN....".
    68. 0060 - 02 fb cd 9e bc 56 9e a3-10 76 fe 3c 93 1b d6 33 .....V...v.<...3
    69. 0070 - 3a 6c 3c f9 96 81 4b 93-e6 84 01 eb 9e 4c 5d bd :l<...K......L].
    70. 0080 - 42 b5 8b 4f 9c 27 a5 f8-4d f9 23 c8 cb cd 91 78 B..O.'..M.#....x
    71. 0090 - 58 8b 40 b4 X.@.
    72.  
    73. Start Time: 1374828368
    74. Timeout : 300 (sec)
    75. Verify return code: 20 (unable to get local issuer certificate)
    76. ---
    77. +OK Gpop ready for requests from 113.161.80.171 w3pf6487545pbz.26
    78. USER <your gmail acount>
    79. +OK send PASS
    80. PASS <your gmail password>
    81. +OK Welcome. LIST //show list of mails
    To copy to clipboard, switch view to plain text mode 

    I want to create an application to run these command automatically and get the final result. My code:

    Qt Code:
    1. process = new QProcess(this);
    2. process->setProcessChannelMode(QProcess::MergedChannels);
    3. args << "s_client" << "-connect" << "pop.gmail.com:995";
    4. process->start("openssl", args);
    5. process->waitForStarted();
    6. process->write("USER <username>\n");
    7. process->write("PASS <password>\n");
    8. process->write("LIST\n");
    9. QString output = process->readAll();
    To copy to clipboard, switch view to plain text mode 

    But the output I get just is:

    Qt Code:
    1. Loading 'screen' into random state -CONNECTED(00000174)---
    2. Certificate chain
    3. 0 s:/C=US/ST=California/L=Mountain View/O=Google Inc/CN=pop.gmail.com
    4. i:/C=US/O=Google Inc/CN=Google Internet Authority
    5. 1 s:/C=US/O=Google Inc/CN=Google Internet Authority
    6. i:/C=US/O=Equifax/OU=Equifax Secure Certificate Authority
    7. ---
    8. Server certificate
    9. -----BEGIN CERTIFICATE-----
    10. MIIDfjCCAuegAwIBAgIKVExoXgABAACEMTANBgkqhkiG9w0BAQUFADBGMQswCQYD
    11. VQQGEwJVUzETMBEGA1UEChMKR29vZ2xlIEluYzEiMCAGA1UEAxMZR29vZ2xlIElu
    12. dGVybmV0IEF1dGhvcml0eTAeFw0xMzA0MTUwODQ1MjVaFw0xMzEyMzExNTU4NTBa
    13. MGcxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1N
    14. b3VudGFpbiBWaWV3MRMwEQYDVQQKEwpHb29nbGUgSW5jMRYwFAYDVQQDEw1wb3Au
    15. Z21haWwuY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDJcFLd/CvEAEYb
    16. PComwfh/VJnV4I0AbErRIBztla7KdaOL3SN8a2lnKKZSkX9fhIMQ8mwCyZ8iWzLG
    17. aXaWr64uChCH2lQNA6O5B/kcLeBfWV51Fwqiq6aRQxpYY7sUqOP03oABRLtBiFOq
    18. wCCLLbkeEcjLuWzzebFk2HX6L++02wIDAQABo4IBUDCCAUwwHQYDVR0lBBYwFAYI
    19. KwYBBQUHAwEGCCsGAQUFBwMCMB0GA1UdDgQWBBS3kDe0ZShOJvpTHlTbh4fjZtVf
    20. lDAfBgNVHSMEGDAWgBS/wDDr9UMRPme6npH7/Gra42sSJDBbBgNVHR8EVDBSMFCg
    21. TqBMhkpodHRwOi8vd3d3LmdzdGF0aWMuY29tL0dvb2dsZUludGVybmV0QXV0aG9y
    22. aXR5L0dvb2dsZUludGVybmV0QXV0aG9yaXR5LmNybDBmBggrBgEFBQcBAQRaMFgw
    23. VgYIKwYBBQUHMAKGSmh0dHA6Ly93d3cuZ3N0YXRpYy5jb20vR29vZ2xlSW50ZXJu
    24. ZXRBdXRob3JpdHkvR29vZ2xlSW50ZXJuZXRBdXRob3JpdHkuY3J0MAwGA1UdEwEB
    25. /wQCMAAwGAYDVR0RBBEwD4INcG9wLmdtYWlsLmNvbTANBgkqhkiG9w0BAQUFAAOB
    26. gQA8MCOlbZZGyLz5byFAq6eFhNw74ahaKVW3QeskRkPUI7hkr37Kmoaq8PE9Oosk
    27. lewH6mgDjheUb6DJJhNhnmcgkAvLfyq0fdDKceSwpTbV5xjcKp3/0G0lzKSMxB7C
    28. oOzEcClsFNLx6EP4FsJS1ELJRGbop7xQF8Wz/5mr88HjFw==
    29. -----END CERTIFICATE-----
    30. subject=/C=US/ST=California/L=Mountain View/O=Google Inc/CN=pop.gmail.com
    31. issuer=/C=US/O=Google Inc/CN=Google Internet Authority
    32. ---
    33. No client certificate CA names sent
    34. ---
    35. SSL handshake has read 2108 bytes and written 443 bytes
    36. ---
    37. New, TLSv1/SSLv3, Cipher is ECDHE-RSA-RC4-SHA
    38. Server public key is 1024 bit
    39. Secure Renegotiation IS supported
    40. Compression: NONE
    41. Expansion: NONE
    42. SSL-Session:
    43. Protocol : TLSv1.2
    44. Cipher : ECDHE-RSA-RC4-SHA
    45. Session-ID: 1C7F9F41B28351AE9C0BD65EC9A235559EE944EDCA6EC30F1D9D3BE12C540B91
    46. Session-ID-ctx:
    47. Master-Key: F4EEF91B5CF9ADC303E544D973A8E804E2E47989B269633B2FE8D02FA68D93269B34F1959C444C228B2481C6EDAC6516
    48. Key-Arg : None
    49. PSK identity: None
    50. PSK identity hint: None
    51. SRP username: None
    52. TLS session ticket lifetime hint: 100800 (seconds)
    53. TLS session ticket:
    54. 0000 - bc 52 af c7 83 85 57 69-f4 c3 11 a5 de 03 b9 ce .R....Wi........
    55. 0010 - 75 27 65 b9 8a fd 34 3e-58 7b ea 25 01 ea d9 3a u'e...4>X{.%...:
    56. 0020 - 84 50 15 9e da d1 f6 a5-3f 7a b9 02 29 67 e3 64 .P......?z..)g.d
    57. 0030 - 6c f9 1e a9 e7 75 11 fe-af f8 3b 91 7d bc cf ab l....u....;.}...
    58. 0040 - cb f0 8f 00 4f b7 a2 a4-e0 06 4f 25 da a9 8e e2 ....O.....O%....
    59. 0050 - 9c 55 f7 4c b4 a7 e2 cd-3c f9 6b 1f bf ec ab c3 .U.L....<.k.....
    60. 0060 - d5 a8 8d a3 dc 0f 26 e1-38 39 e6 2b bb 71 40 8d ......&.89.+.q@.
    61. 0070 - 95 1e 3a 71 6a fa 64 84-2b 42 92 36 f3 fb 93 b3 ..:qj.d.+B.6....
    62. 0080 - ba ec 6f e5 48 50 ea 6f-23 4d 2b 5b f4 9c 8a 58 ..o.HP.o#M+[...X
    63. 0090 - 31 24 b5 c0 1$..
    64.  
    65. Start Time: 1374828292
    66. Timeout : 300 (sec)
    67. Verify return code: 20 (unable to get local issuer certificate)
    68. --- +OK Gpop ready for requests from 113.161.80.171 on1pf6530043pbc.6
    To copy to clipboard, switch view to plain text mode 

    This means the lines from USER have not been executed. It seems to be in a session while waiting for USER and PASS after "+OK Gpop ready for requests from 113.161.80.171 on1pf6530043pbc.6" line and our current QProcess can not write anything into. Anyone can help me on this? I am e newbie in Qt so I do not know much about QProcess.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Execute window command line-by-line using QProcess

    QIODevice relies on the Qt event loop to process writes to the subprocess, and that is not functioning here. You need to waitForBytesWritten()/waitForBytesRead(), or you need to write using asynchronous methods. Here is a very crude example:
    Qt Code:
    1. #include <QtCore>
    2.  
    3. class PopLister: public QObject
    4. {
    5. Q_OBJECT
    6. public:
    7. enum State { Starting, SentUser, SentPass, SentList, ReadList, Stopping };
    8.  
    9. explicit PopLister(QObject *p = 0):
    10. QObject(p),
    11. process(new QProcess(this)),
    12. state(Starting)
    13. {
    14. process->setProcessChannelMode(QProcess::MergedChannels);
    15. connect(process, SIGNAL(readyRead()), SLOT(handleOutput()));
    16. }
    17.  
    18. void start()
    19. {
    20. args << "s_client" << "-connect" << "server:995";
    21. process->start("openssl", args);
    22. state = Starting;
    23. }
    24.  
    25. private slots:
    26. void handleOutput() {
    27. while (process->canReadLine()) {
    28. QByteArray line = process->readLine();
    29.  
    30. if (line.startsWith("+OK")) {
    31. switch (state) {
    32. case Starting:
    33. process->write("USER username\r\n");
    34. state = SentUser;
    35. break;
    36. case SentUser:
    37. process->write("PASS password\r\n");
    38. state = SentPass;
    39. break;
    40. case SentPass:
    41. listData.clear();
    42. process->write("LIST\r\n");
    43. state = SentList;
    44. break;
    45. case SentList:
    46. state = ReadList;
    47. break;
    48. case ReadList: // suppress compiler warnings
    49. case Stopping:
    50. break;
    51. }
    52. }
    53. else if(line.startsWith("-ERR")) {
    54. qDebug() << line;
    55. process->write("QUIT\r\n");
    56. state = Stopping;
    57. }
    58. else if (state == ReadList) {
    59. if (line == ".\r\n") {
    60. qDebug() << listData;
    61. process->write("QUIT\r\n");
    62. state = Stopping;
    63. }
    64. else {
    65. listData += line;
    66. }
    67. }
    68. else if (state == Stopping) {
    69. qDebug() << line;
    70. }
    71. }
    72. }
    73. private:
    74. QProcess *process;
    75. State state;
    76. QByteArray listData;
    77. };
    78.  
    79. int main(int argc, char **argv)
    80. {
    81. QCoreApplication app(argc, argv);
    82. PopLister lister;
    83. lister.start();
    84. return app.exec();
    85. }
    86. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to ChrisW67 for this useful post:

    nhocjerry (29th July 2013)

  4. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Execute window command line-by-line using QProcess

    Also some POP servers will discard everything that was sent to them prior to their last response. Thus if you send data blindly before the data is requested, the data will be ignored (at best).

    By the way, why would anyone want to write a program that talks to gmail over openssl console? Why not use QSslSocket?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. The following user says thank you to wysota for this useful post:

    nhocjerry (29th July 2013)

  6. #4
    Join Date
    Jul 2013
    Posts
    9
    Thanks
    5

    Default Re: Execute window command line-by-line using QProcess

    Quote Originally Posted by ChrisW67 View Post
    QIODevice relies on the Qt event loop to process writes to the subprocess, and that is not functioning here. You need to waitForBytesWritten()/waitForBytesRead(), or you need to write using asynchronous methods. Here is a very crude example:
    Qt Code:
    1. #include <QtCore>
    2.  
    3. class PopLister: public QObject
    4. {
    5. Q_OBJECT
    6. public:
    7. enum State { Starting, SentUser, SentPass, SentList, ReadList, Stopping };
    8.  
    9. explicit PopLister(QObject *p = 0):
    10. QObject(p),
    11. process(new QProcess(this)),
    12. state(Starting)
    13. {
    14. process->setProcessChannelMode(QProcess::MergedChannels);
    15. connect(process, SIGNAL(readyRead()), SLOT(handleOutput()));
    16. }
    17.  
    18. void start()
    19. {
    20. args << "s_client" << "-connect" << "server:995";
    21. process->start("openssl", args);
    22. state = Starting;
    23. }
    24.  
    25. private slots:
    26. void handleOutput() {
    27. while (process->canReadLine()) {
    28. QByteArray line = process->readLine();
    29.  
    30. if (line.startsWith("+OK")) {
    31. switch (state) {
    32. case Starting:
    33. process->write("USER username\r\n");
    34. state = SentUser;
    35. break;
    36. case SentUser:
    37. process->write("PASS password\r\n");
    38. state = SentPass;
    39. break;
    40. case SentPass:
    41. listData.clear();
    42. process->write("LIST\r\n");
    43. state = SentList;
    44. break;
    45. case SentList:
    46. state = ReadList;
    47. break;
    48. case ReadList: // suppress compiler warnings
    49. case Stopping:
    50. break;
    51. }
    52. }
    53. else if(line.startsWith("-ERR")) {
    54. qDebug() << line;
    55. process->write("QUIT\r\n");
    56. state = Stopping;
    57. }
    58. else if (state == ReadList) {
    59. if (line == ".\r\n") {
    60. qDebug() << listData;
    61. process->write("QUIT\r\n");
    62. state = Stopping;
    63. }
    64. else {
    65. listData += line;
    66. }
    67. }
    68. else if (state == Stopping) {
    69. qDebug() << line;
    70. }
    71. }
    72. }
    73. private:
    74. QProcess *process;
    75. State state;
    76. QByteArray listData;
    77. };
    78.  
    79. int main(int argc, char **argv)
    80. {
    81. QCoreApplication app(argc, argv);
    82. PopLister lister;
    83. lister.start();
    84. return app.exec();
    85. }
    86. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 
    Thanks for your reply. However, it doesn't work, it still pause at "+OK Gpop ready for requests from 113.161.80.171 on1pf6530043pbc.6"


    Added after 14 minutes:


    Quote Originally Posted by wysota View Post
    Also some POP servers will discard everything that was sent to them prior to their last response. Thus if you send data blindly before the data is requested, the data will be ignored (at best).

    By the way, why would anyone want to write a program that talks to gmail over openssl console? Why not use QSslSocket?
    I found it more easier when use QSslSocket, thank you so much. Here is my code:

    sslsocket.h
    Qt Code:
    1. #include <QMainWindow>
    2. #include <QSslSocket>
    3.  
    4. namespace Ui {
    5. class SslSocket;
    6. }
    7.  
    8. class SslSocket : public QMainWindow
    9. {
    10. Q_OBJECT
    11.  
    12. public:
    13. explicit SslSocket(QWidget *parent = 0);
    14. ~SslSocket();
    15.  
    16. private:
    17. Ui::SslSocket *ui;
    18.  
    19. QSslSocket *sslSocket;
    20.  
    21. QString output;
    22.  
    23. QString serverAddress;
    24.  
    25. int port;
    26.  
    27. private slots:
    28. void encrypted();
    29.  
    30. void readyRead();
    31.  
    32. void on_btnGetData_clicked();
    33. };
    To copy to clipboard, switch view to plain text mode 

    sslsocket.cpp
    Qt Code:
    1. #include "sslsocket.h"
    2. #include "ui_sslsocket.h"
    3.  
    4. SslSocket::SslSocket(QWidget *parent) :
    5. QMainWindow(parent),
    6. ui(new Ui::SslSocket)
    7. {
    8. ui->setupUi(this);
    9.  
    10. sslSocket = new QSslSocket(this);
    11.  
    12. connect(sslSocket, SIGNAL(encrypted()), this, SLOT(encrypted()));
    13. connect(sslSocket, SIGNAL(readyRead()), this, SLOT(readyRead()));
    14.  
    15. port = 995;
    16. serverAddress = "pop.gmail.com";
    17. sslSocket->connectToHostEncrypted(serverAddress, port);
    18.  
    19. }
    20.  
    21. SslSocket::~SslSocket()
    22. {
    23. delete ui;
    24. }
    25.  
    26. void SslSocket::encrypted()
    27. {
    28. QMessageBox::information(this, "Info", "Encrypted!");
    29. }
    30.  
    31. void SslSocket::readyRead()
    32. {
    33. QString data(sslSocket->readAll());
    34.  
    35. output += data;
    36.  
    37. ui->txtOutput->setText(output);
    38. }
    39.  
    40. void SslSocket::on_btnGetData_clicked()
    41. {
    42. QByteArray byteArray("USER ");
    43. byteArray.append("<username>");
    44. sslSocket->write(byteArray);
    45. sslSocket->write("\r\n");
    46.  
    47. sslSocket->waitForReadyRead();
    48.  
    49. byteArray.clear();
    50. byteArray.append("PASS ");
    51. byteArray.append("<password>");
    52. sslSocket->write(byteArray);
    53. sslSocket->write("\r\n");
    54.  
    55. sslSocket->waitForReadyRead();
    56.  
    57. byteArray.clear();
    58. byteArray.append("LIST");
    59. sslSocket->write(byteArray);
    60. sslSocket->write("\r\n");
    61. }
    To copy to clipboard, switch view to plain text mode 

    It works fine for me, but I have another mail server: mail.simplessus.com. When I replace "pop.gmail.com" by this server address, it can not read any data out. It also doesn't emit encrypted() slot as well as readyRead() slot. Is there something wrong with the mail server? Or I have to use another function to get the data? Thanks so much again
    Last edited by nhocjerry; 29th July 2013 at 13:22.

  7. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Execute window command line-by-line using QProcess

    However, it doesn't work, it still pause at "+OK Gpop ready for requests from 113.161.80.171 on1pf6530043pbc.6"
    The code works perfectly well against my local POP3 server and a Gmail account I set up specifically for the purpose. Here is the output for my newly minted GMail account:
    Qt Code:
    1. "1 15714
    2. 2 16805
    3. 3 9094
    4. 4 9107
    5. "
    6. "DONE
    7. "
    To copy to clipboard, switch view to plain text mode 
    The first 4 lines are the LIST output. "DONE" is in response to QUIT. I suggest you try analysing the actual problem.
    Incidentally, the same code should work with a QSslSocket in place of QProcess: both are QIODevice subclasses.

    It works fine for me, but I have another mail server: mail.simplessus.com. When I replace "pop.gmail.com" by this server address, it can not read any data out. It also doesn't emit encrypted() slot as well as readyRead() slot. Is there something wrong with the mail server? Or I have to use another function to get the data?
    No encrypted() signal -> no encryption. If the server is supposed to offering encrypted service then it is misconfigured, expecting the STLS command (Start TLS), or you are connecting to an unencrypted port.

    waitForReadyRead() will return as soon as there is any data available to read. Note, this is not an all-the-data-is-received signal, so you may well be sending your next command before the server is expecting it. See wysota's comment regarding that.

  8. #6
    Join Date
    Jul 2013
    Posts
    9
    Thanks
    5

    Default Re: Execute window command line-by-line using QProcess


    No encrypted() signal -> no encryption. If the server is supposed to offering encrypted service then it is misconfigured, expecting the STLS command (Start TLS), or you are connecting to an unencrypted port.

    waitForReadyRead() will return as soon as there is any data available to read. Note, this is not an all-the-data-is-received signal, so you may well be sending your next command before the server is expecting it. See wysota's comment regarding that.
    Ok, I have found the problem, the mail server is not support ssl port, I used port 143 and everthing is OK now. Thanks for support

Similar Threads

  1. Replies: 1
    Last Post: 30th March 2012, 16:35
  2. Replies: 3
    Last Post: 9th March 2011, 13:52
  3. Replies: 7
    Last Post: 15th November 2010, 10:00
  4. QProcess and the command line
    By auba in forum Qt Programming
    Replies: 17
    Last Post: 27th May 2009, 11:39
  5. Is there a command-line window in Qt4?
    By miaoliang in forum Qt Programming
    Replies: 2
    Last Post: 8th November 2006, 09:56

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.