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
Code:
system ( "/root/stego/encrypt.sh >& /root/stego/error.txt" );
textBrowser->clear();
textBrowser->setSource( "/root/stego/error.txt") ;
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
Code:
void steg::encrypt()
{
char encrypt_comand[]= "-e";
char key_comand[]= "-k=";
s3 << encrypt_comand << ui.datalineEdit->text() << "coded.txt" << ( key_comand + ui.passphraselineEdit->text() );
}
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.
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().
Re: How To Redirect The Console Output To A Text Browser/pop Up
I have tried the following
Code:
void steg::encrypt()
{
char encrypt_comand[]= "-e";
char key_comand[]= "-k=";
s3 << encrypt_comand << ui.datalineEdit->text() << "coded.txt" << ( key_comand + ui.passphraselineEdit->text() );
P
->startDetached
( QString("burp.exe"),s3
);
QString result_all
= P
->readAllStandardOutput
();
//QMessageBox::about(this, tr("JPSTEGO"),tr(result_all.toAscii()));
file.setFileName("showjpegfile.txt");
out << result_all.toAscii();
ui.textEdit->insertPlainText(result_all);
}
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.
Re: How To Redirect The Console Output To A Text Browser/pop Up
Quote:
Originally Posted by
deekayt
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:
Code:
P->start( "burp.exe", s3 );
P->waitForFinished();
QString result_all
= P
->readAllStandardOutput
();
and make sure that this "burp" thing writes to standard output, not standard error stream.
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
Code:
void steg::encrypt()
{
char encrypt_comand[]= "-e";
char key_comand[]= "-k=";
s3 << encrypt_comand << ui.datalineEdit->text() << "coded.txt" << ( key_comand + ui.passphraselineEdit->text() );
P
->start
( QString("burp.exe"),s3
);
P->waitForFinished();
QString result_all
= P
->readAllStandardOutput
();
ui.textBrowser->setSource( result_all);
}
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
Code:
file.setFileName("showjpegfile.txt");
out << result_all; //NOTHING HAPPENED
ui.textEdit->textCursor().insertText(result_all); //NOTHING HAPPENED
How can I try to put in the message box
I tried the code below.But it doesnot work.
Code:
tr("<p>The <b>JPSTEGO</b> is a data hiding and extraction software"
"forhiding data while converting image files to JPEG format",
+result_all));
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?
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
Code:
void steg::encrypt()
{
char encrypt_comand[]= "-e";
char key_comand[]= "-k=";
s3 << encrypt_comand << ui.datalineEdit->text() << "coded.txt" << ( key_comand + ui.passphraselineEdit->text() );
P
->setReadChannelMode
(QProcess::MergedChannels);
P
->start
( QString("burp.exe"),s3
);
P->waitForFinished();
QString result_all
= P
->readAllStandardOutput
();
//QDir::setCurrent("E:");
file.setFileName("encrypt_error.html");
out << result_all;
file.close();
ui.textBrowser->clear();
myurl1
=QUrl::fromLocalFile( "encrypt_error.html" ) ;
ui.textBrowser->setSource(myurl1);
}
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.
Re: How To Redirect The Console Output To A Text Browser/pop Up
Quote:
Originally Posted by
deekayt
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
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()
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
Code:
void steg::encrypt()
{
char encrypt_comand[]= "-e";
char key_comand[]= "-k=";
s3 << encrypt_comand << ui.datalineEdit->text() << "coded.txt" << ( key_comand + ui.passphraselineEdit->text() );
P
->setReadChannelMode
(QProcess::MergedChannels);
P
->start
( QString("burp.exe"),s3
);
P->waitForFinished();
QString result_all
= P
->readAllStandardOutput
();
//QDir::setCurrent("E:");
file.setFileName("encrypt_error.html");
out << result_all;
file.close();
ui.textBrowser->clear();
myurl1
=QUrl::fromLocalFile( "encrypt_error.html" ) ;
ui.textBrowser->setSource(myurl1);
}
I had to use it for another exe program that is cjpeg.exe. I used the following code
Code:
void steg::stego()
{
char steg_comand[]= "-steg";
char q_comand[]= "-q";
s2 << steg_comand << "coded.txt" << q_comand << ui.compressionspinBox->text() << ui.imagelineEdit->text() << ui.jpeglineEdit ->text() ;
P1
->setReadChannelMode
(QProcess::MergedChannels);
P1
->start
( QString("cjpeg.exe"),s2
);
P1->waitForFinished();
QString result_hide
= P1
->readAllStandardOutput
();
//QDir::setCurrent("E:");
file1.setFileName("hide_error.html");
out << result_hide;
file1.close();
myurl2
=QUrl::fromLocalFile( "hide_error.html" ) ;
ui.textBrowser->setSource(myurl2);
}
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.
Re: How To Redirect The Console Output To A Text Browser/pop Up
Quote:
Originally Posted by
deekayt
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?
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
Code:
void steg::stego()
{
/*char steg_comand[]= "-steg";
char q_comand[]= "-q";
QStringList s2;
s2 << steg_comand << "coded.txt" << q_comand << ui.compressionspinBox->text() << ui.imagelineEdit->text() << ui.jpeglineEdit ->text() ;
P1->setReadChannelMode(QProcess::MergedChannels);
P1->start( QString("cjpeg.exe"),s2 ); */
P1
->start
(QString("stego.bat")); OR P1
->startDetached
(QString("stego.bat"));
P1->waitForFinished();
QString result_hide
= P1
->readAllStandardOutput
();
//QDir::setCurrent("E:");
file1.setFileName("hide_error.html");
out << result_hide;
file1.close();
//ui.textBrowser->clear();
myurl2
=QUrl::fromLocalFile( "hide_error.html" ) ;
ui.textBrowser->setSource(myurl2);
}
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.
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.
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();
Re: How To Redirect The Console Output To A Text Browser/pop Up
Quote:
Originally Posted by
deekayt
changing cjpeg.exe is out of question
I didn't write anything about changing cjpeg.exe.
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
Re: How To Redirect The Console Output To A Text Browser/pop Up
Quote:
Originally Posted by
deekayt
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.
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();
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.
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
Re: How To Redirect The Console Output To A Text Browser/pop Up
At Which Email Should I Send 2 Mb Zip File.