Page 1 of 3 123 LastLast
Results 1 to 20 of 53

Thread: How To Redirect The Console Output To A Text Browser/pop Up

  1. #1
    Join Date
    May 2006
    Posts
    68
    Thanks
    10
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default How To Redirect The Console Output To A Text Browser/pop Up

    I am running an external process ( dos exe file runnable on command prompt) through Q process
    I need to capture the error messages and either display them in the text browser ( which is static in my form) or make custom made message (depending on what the exe program has given ) and then display them in the textbrowser/popUP

    Earlier I was able to do so in qt3.3.4 on linux with the following code

    Qt Code:
    1. system ( "/root/stego/encrypt.sh >& /root/stego/error.txt" );
    2. textBrowser->clear();
    3. textBrowser->setSource( "/root/stego/error.txt") ;
    To copy to clipboard, switch view to plain text mode 

    where I was running the command prompt command through a script file ( encrypt.sh in above case) and redirecting the screen output to error .txt and then redirecting it to text browser.

    Now in qt 4 ( windows) I am using the Qprocess as under

    Qt Code:
    1. void steg::encrypt()
    2. {
    3. char encrypt_comand[]= "-e";
    4. char key_comand[]= "-k=";
    5. s3 << encrypt_comand << ui.datalineEdit->text() << "coded.txt" << ( key_comand + ui.passphraselineEdit->text() );
    6. QProcess::startDetached( QString("burp.exe"),s3 );
    7.  
    8. }
    To copy to clipboard, switch view to plain text mode 
    The burp.exe is command prompt command and gives the ok/error messages on the screen ( on console). How to direct the same to a text file.Then compare and show a custom message say in a text browser or I can even resort to pop message( why not?/let me improve with qt 4)

    Thanks in advance for the guidance.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How To Redirect The Console Output To A Text Browser/pop Up

    You can use QProcess::readAllStandardOutput() and QProcess::readAllStandardError() to read the data. QProcess::readyReadStandardError() and QProcess::readyReadStandardOutput () signals will be emitted when the data is available.

    Of course you will have to use QProcess instance, instead of QProcess::startDetached().

  3. #3
    Join Date
    May 2006
    Posts
    68
    Thanks
    10
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How To Redirect The Console Output To A Text Browser/pop Up

    I have tried the following

    Qt Code:
    1. void steg::encrypt()
    2. {
    3. QProcess *P =new QProcess ;
    4. char encrypt_comand[]= "-e";
    5. char key_comand[]= "-k=";
    6. s3 << encrypt_comand << ui.datalineEdit->text() << "coded.txt" << ( key_comand + ui.passphraselineEdit->text() );
    7. P->startDetached( QString("burp.exe"),s3 );
    8. QString result_all = P->readAllStandardOutput();
    9. //QMessageBox::about(this, tr("JPSTEGO"),tr(result_all.toAscii()));
    10.  
    11.  
    12. QFile file;
    13.  
    14. file.setFileName("showjpegfile.txt");
    15. file.open(QIODevice::WriteOnly);
    16.  
    17. QTextStream out(&file);
    18. out << result_all.toAscii();
    19.  
    20. ui.textEdit->insertPlainText(result_all);
    21.  
    22. }
    To copy to clipboard, switch view to plain text mode 

    First I tried to take the Qstring and display in the message box. Nothing happened . Message box comes up but no message is there. Though burp .exe gets executed and gives msg everytime on the command prompt.
    Then I tried to redirect the console output to a file and put in a textedit( not a clean way)but it also didnot work.

    I am only sure that burp.exe gets executed sinceI find files encrypted as required.I am also sure that some console output always comes. But after that I am not able to find out the problem.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How To Redirect The Console Output To A Text Browser/pop Up

    Quote Originally Posted by deekayt View Post
    P->startDetached( QString("burp.exe"),s3 );
    QString result_all = P->readAllStandardOutput();
    I've already told you two times, that QProcess::startDetached() is a static method. There is no sense in invoking it on an object.

    Try:
    Qt Code:
    1. P->start( "burp.exe", s3 );
    2. P->waitForFinished();
    3. QString result_all = P->readAllStandardOutput();
    To copy to clipboard, switch view to plain text mode 
    and make sure that this "burp" thing writes to standard output, not standard error stream.

  5. #5
    Join Date
    May 2006
    Posts
    68
    Thanks
    10
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How To Redirect The Console Output To A Text Browser/pop Up

    My requirement is to get the console output to the text browser.( Message box and text edit)
    I have tried the following code

    Qt Code:
    1. void steg::encrypt()
    2. {
    3. QProcess *P =new QProcess ;
    4. char encrypt_comand[]= "-e";
    5. char key_comand[]= "-k=";
    6. s3 << encrypt_comand << ui.datalineEdit->text() << "coded.txt" << ( key_comand + ui.passphraselineEdit->text() );
    7. P->start( QString("burp.exe"),s3 );
    8. P->waitForFinished();
    9. QString result_all= P->readAllStandardOutput();
    10. ui.textBrowser->setSource( result_all);
    11. }
    To copy to clipboard, switch view to plain text mode 
    But it did not work . Then I tried to write the Qstring result_all to a file and then see the file manually.The file gets created but nothing is written to file. That means nothing is in QString result_ all . Then I tried to see that the Qstring result_all is put in the tetxEdit ( since setText is there and perhaps Url thing might be giving problem in TextBrowser) But that also did not work. Those codes are down below


    Qt Code:
    1. QFile file;
    2. file.setFileName("showjpegfile.txt");
    3. file.open(QIODevice::WriteOnly);
    4. QTextStream out(&file);
    5. out << result_all; //NOTHING HAPPENED
    6.  
    7. ui.textEdit->textCursor().insertText(result_all); //NOTHING HAPPENED
    To copy to clipboard, switch view to plain text mode 
    How can I try to put in the message box
    I tried the code below.But it doesnot work.


    Qt Code:
    1. QMessageBox::about(this, tr("About JPSTEGO"),
    2. tr("<p>The <b>JPSTEGO</b> is a data hiding and extraction software"
    3. "forhiding data while converting image files to JPEG format",
    4. +result_all));
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How To Redirect The Console Output To A Text Browser/pop Up

    Does P->waitForFinished() return true? Does "burb.exe" write data to standard output?

  7. #7
    Join Date
    May 2006
    Posts
    68
    Thanks
    10
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How To Redirect The Console Output To A Text Browser/pop Up

    While I was awaiting your reply I tinkered with the code and was able to figure out the error.
    In fact burp.exe was writing to standard error channel instead of standard output. I then further improved it to merge the channels and the code is as
    below

    Qt Code:
    1. void steg::encrypt()
    2. {
    3. QProcess *P =new QProcess ;
    4. char encrypt_comand[]= "-e";
    5. char key_comand[]= "-k=";
    6. s3 << encrypt_comand << ui.datalineEdit->text() << "coded.txt" << ( key_comand + ui.passphraselineEdit->text() );
    7. P->setReadChannelMode(QProcess::MergedChannels);
    8. P->start( QString("burp.exe"),s3 );
    9. P->waitForFinished();
    10. QString result_all= P->readAllStandardOutput();
    11. QFile file;
    12. //QDir::setCurrent("E:");
    13. file.setFileName("encrypt_error.html");
    14. file.open(QIODevice::WriteOnly);
    15.  
    16. QTextStream out(&file);
    17. out << result_all;
    18. file.close();
    19. ui.textBrowser->clear();
    20. QUrl myurl1;
    21. myurl1=QUrl::fromLocalFile( "encrypt_error.html" ) ;
    22. ui.textBrowser->setSource(myurl1);
    23.  
    24. }
    To copy to clipboard, switch view to plain text mode 
    1. Now I am able to get whatever is the output to the textBrowser . But I believe there would be better way without getting through the file thing. Could you suggest a better method.

    2. Moreover I want to output to textbrowser the messages defined by me after comparing what is the output of these exe processes. Is there a method in QT to compare the message, or look for a string and then make own message or delete a part of the message or append a part from the user side and then get it to the textbrowser.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How To Redirect The Console Output To A Text Browser/pop Up

    Quote Originally Posted by deekayt View Post
    Now I am able to get whatever is the output to the textBrowser . But I believe there would be better way without getting through the file thing. Could you suggest a better method.
    QTextEdit::setPlainText() or QTextEdit::setHtml()

    Quote Originally Posted by deekayt View Post
    Moreover I want to output to textbrowser the messages defined by me after comparing what is the output of these exe processes. Is there a method in QT to compare the message, or look for a string and then make own message or delete a part of the message or append a part from the user side and then get it to the textbrowser.
    QRegExp and QString::find()

  9. The following user says thank you to jacek for this useful post:

    deekayt (4th November 2006)

  10. #9
    Join Date
    May 2006
    Posts
    68
    Thanks
    10
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How To Redirect The Console Output To A Text Browser/pop Up

    Now I am facing a peculiar problem .
    After resolving the issue of burp.exe with the following code
    Qt Code:
    1. void steg::encrypt()
    2. {
    3. QProcess *P =new QProcess ;
    4. char encrypt_comand[]= "-e";
    5. char key_comand[]= "-k=";
    6. s3 << encrypt_comand << ui.datalineEdit->text() << "coded.txt" << ( key_comand + ui.passphraselineEdit->text() );
    7. P->setReadChannelMode(QProcess::MergedChannels);
    8. P->start( QString("burp.exe"),s3 );
    9. P->waitForFinished();
    10. QString result_all= P->readAllStandardOutput();
    11. QFile file;
    12. //QDir::setCurrent("E:");
    13. file.setFileName("encrypt_error.html");
    14. file.open(QIODevice::WriteOnly);
    15. QTextStream out(&file);
    16. out << result_all;
    17. file.close();
    18. ui.textBrowser->clear();
    19. QUrl myurl1;
    20. myurl1=QUrl::fromLocalFile( "encrypt_error.html" ) ;
    21. ui.textBrowser->setSource(myurl1);
    22. }
    To copy to clipboard, switch view to plain text mode 

    I had to use it for another exe program that is cjpeg.exe. I used the following code

    Qt Code:
    1. void steg::stego()
    2. {
    3. QProcess *P1 =new QProcess ;
    4. char steg_comand[]= "-steg";
    5. char q_comand[]= "-q";
    6. s2 << steg_comand << "coded.txt" << q_comand << ui.compressionspinBox->text() << ui.imagelineEdit->text() << ui.jpeglineEdit ->text() ;
    7. P1->setReadChannelMode(QProcess::MergedChannels);
    8. P1->start( QString("cjpeg.exe"),s2 );
    9. P1->waitForFinished();
    10. QString result_hide= P1->readAllStandardOutput();
    11. QFile file1;
    12. //QDir::setCurrent("E:");
    13. file1.setFileName("hide_error.html");
    14. file1.open(QIODevice::WriteOnly);
    15. QTextStream out(&file1);
    16. out << result_hide;
    17. file1.close();
    18.  
    19. QUrl myurl2;
    20. myurl2=QUrl::fromLocalFile( "hide_error.html" ) ;
    21. ui.textBrowser->setSource(myurl2);
    22. }
    To copy to clipboard, switch view to plain text mode 
    The above code is suppose to convert a .ppm(image file) to jpeg while hiding a text file in it. If all is ok then no output is thrown on the console else one gets an error message.
    I deliberately choose parameters to generate the error message but i get blank hide_error.html(which do get created everytime). cjpeg.exe does work since when all parameters are ok I get the jpeg file made. When I run the cjpeg command on command prompt or through a .bat file i get the messages on the console.
    In order to verify the code I just replaced cjpeg.exe with burp.exe and i immediately got the error message of burp in my text browser. I know the problem is with cjpeg.exe.But the same thing is fine on command prompt. In fact it is runing even through this code since i got the desired file ( as output ) . I donot know what is the problem.
    Could u tell please me How to debug and resolve??
    I have been trying forlast three days, but no luck.

  11. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How To Redirect The Console Output To A Text Browser/pop Up

    Quote Originally Posted by deekayt View Post
    I know the problem is with cjpeg.exe.But the same thing is fine on command prompt. In fact it is runing even through this code since i got the desired file ( as output ) . I donot know what is the problem.
    Maybe that cjpeg program detects that it wasn't started from the console and sits quietly?

  12. #11
    Join Date
    May 2006
    Posts
    68
    Thanks
    10
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How To Redirect The Console Output To A Text Browser/pop Up

    Probably that is the problem.I am sure it is not behaving as a normal .exe
    I tried to run it through a bat (stego.bat)file in which i wrote the command cjpeg

    The code was as

    Qt Code:
    1. void steg::stego()
    2. {
    3. QProcess *P1 =new QProcess ;
    4. /*char steg_comand[]= "-steg";
    5.   char q_comand[]= "-q";
    6.  
    7.   QStringList s2;
    8.  
    9.   s2 << steg_comand << "coded.txt" << q_comand << ui.compressionspinBox->text() << ui.imagelineEdit->text() << ui.jpeglineEdit ->text() ;
    10.  
    11.   P1->setReadChannelMode(QProcess::MergedChannels);
    12.  
    13.   P1->start( QString("cjpeg.exe"),s2 ); */
    14.  
    15. P1->start(QString("stego.bat")); OR P1->startDetached(QString("stego.bat"));
    16. P1->waitForFinished();
    17. QString result_hide= P1->readAllStandardOutput();
    18.  
    19. QFile file1;
    20. //QDir::setCurrent("E:");
    21. file1.setFileName("hide_error.html");
    22. file1.open(QIODevice::WriteOnly);
    23.  
    24. QTextStream out(&file1);
    25. out << result_hide;
    26. file1.close();
    27. //ui.textBrowser->clear();
    28. QUrl myurl2;
    29. myurl2=QUrl::fromLocalFile( "hide_error.html" ) ;
    30. ui.textBrowser->setSource(myurl2);
    31. }
    To copy to clipboard, switch view to plain text mode 

    When I used P1->start(QString("stego.bat)); the dos screen appeared and I found the error message(as it should have come) and then the screen disappeared since I have not put any code to stop that. It means there was output to console as I want it . But it didnot get captured to QString result_all . How can I capture it (but keeping only start()) and then redirect to textbrowser.

    when I used P1->startDetached (QString("stego.bat)); as expected no screen appeared and the cjpeg command did not run. And interestingly i get the out put as

    C:\Qt\4.1.3\stegform1\release>cjpeg

    where "C:\Qt\4.1.3\stegform1\release" is the current directory and cjpeg is thecommand written in stego.bat. If i could simulate "enter" after cjpeg in stego.bat perhaps it would have executed.
    Can u suggest a way out. I cannot change cjpeg.exe.

  13. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How To Redirect The Console Output To A Text Browser/pop Up

    If you have access to cjpeg sources, you could check why it behaves like that and maybe you will find a way to fool it.

  14. #13
    Join Date
    May 2006
    Posts
    68
    Thanks
    10
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How To Redirect The Console Output To A Text Browser/pop Up

    changing cjpeg.exe is out of question
    how can i have Qprocess -> start() and still read the std out puts.that perhaps may solve the problem.also with Qprocess-> start() how to keep the console screen on instead of closing on its own.Like we useto stop the screen with getchar();

  15. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How To Redirect The Console Output To A Text Browser/pop Up

    Quote Originally Posted by deekayt View Post
    changing cjpeg.exe is out of question
    I didn't write anything about changing cjpeg.exe.

  16. #15
    Join Date
    May 2006
    Posts
    68
    Thanks
    10
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How To Redirect The Console Output To A Text Browser/pop Up

    Dear JACEK
    my Query is not still answered.Do tell how to circumvent this problem.
    That is the last thing left in my project .
    I know you can get me out of this.
    Thanks

  17. #16
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How To Redirect The Console Output To A Text Browser/pop Up

    Quote Originally Posted by deekayt View Post
    my Query is not still answered.Do tell how to circumvent this problem.
    I've already told you: take a look at cjpeg sources and see why it behaves like that, then you can look for a solution.

  18. #17
    Join Date
    May 2006
    Posts
    68
    Thanks
    10
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How To Redirect The Console Output To A Text Browser/pop Up

    how can i have Qprocess -> start() and still read the std out puts.that perhaps may solve the problem.also with Qprocess-> start() how to keep the console screen on instead of closing on its own.Like we useto stop the screen with getchar();

  19. #18
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How To Redirect The Console Output To A Text Browser/pop Up

    I've found some cjpeg.exe in the Internet (here) and tested it with Qt 4.1.5 on windows and I had no problem to capture its output.

    So either:
    • you have some other cjpeg.exe that behaves in a different way,
    • your cjpeg is compiled in a weird way,
    • there's something wrong with your program.

  20. The following user says thank you to jacek for this useful post:

    deekayt (15th November 2006)

  21. #19
    Join Date
    May 2006
    Posts
    68
    Thanks
    10
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How To Redirect The Console Output To A Text Browser/pop Up

    JACEK
    I must thank you for all the pains you would have taken to look for CJPEG.EXE on the net and then testing it.
    Infact this CJPEG.EXE is from Independent JPEG group ( VERSION 6) .The same program ( VERSION 4) has been modified for data hiding in JPEG images. ANd some more switches have been provided.
    Now instead of just converting a PPM file to JPEG one can add a data file with -steg switch in the JPEG file so formed.( This modification perhaps has not been done in VERSION 6 )

    cjpeg -steg <filename> image.ppm image2.jpg

    is the way it works.
    Now there is a limit to the amount of data one can hide in the JPEG file. When all the filenames are OK and data to be hidden is not exceeding there is no message meaning the thing has worked fine.
    But if the data is too much to be loaded or <filename> or image.ppm is missing then the error message come. Now this happens on the comd prompt and not through my program.
    I couldhave attached the zipped file but it is 2 mb.I am sending it in email. Please have a look at it.You have brought me till here.Thanks

  22. #20
    Join Date
    May 2006
    Posts
    68
    Thanks
    10
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How To Redirect The Console Output To A Text Browser/pop Up

    At Which Email Should I Send 2 Mb Zip File.

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 10:49
  2. No output to console
    By Morea in forum Newbie
    Replies: 6
    Last Post: 1st November 2007, 23:51
  3. No console output in Mac OSX using Qt4
    By popoholic in forum Qt Programming
    Replies: 2
    Last Post: 26th September 2006, 02:36

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.