I am currently building a GUI and would like to have a window that displays standard output commands. Is there a class I can utilize to do this or should I turn all my standard output commands to file output commands and display the text file? Any insight is greatly appreciated.
Thank you for your quick response.
I’m sorry, but I’m still unsure how to do this. Is there a function in TGTextView that will do it directly? Also, I tried looking at TBrowser.cxx to see how it’s done in TBrowser, but I wasn’t able to find that section of code. Did I just overlook it or am I looking in the wrong place?
I’m still trying to figure out how to do this. I looked at the TGCommandPlugin class and found the HandleCommand function. I’m working on using this code as a model where const char *string is assigned the contents of cout. Is this close to a correct approach?
OK, here is an example of how to get the result of a command in a TGTextView:
std::string line;
std::istringstream iss(gSystem->GetFromPipe(command).Data());
while (std::getline(iss, line)) {
fTextView->AddLine(line.c_str());
}
fTextView->ShowBottom();
You can also redirect the output to a file (as it is done in TGCommandPlugin.cxx). Here is a simplified example:
I’m getting an error message saying “cannot open file ‘TGTextViewStream.h’”. I’m in the directory where I’ve run all the other root tutorials so I don’t think any paths should be a problem, but I may be missing something. Any advice?
I have another related question: Is there a way to print cout statements from cxx files to the text viewer by a means other than rewriting every cout statement with a TGTextView AddLine() function? Or is this possible with the example code provided, and I just don’t see it.
[quote=“jito”]No problem! Thank you. It works now.[/quote]You’re welcome
[quote=“jito”]Is there a way to print cout statements from cxx files to the text viewer by a means other than rewriting every cout statement with a TGTextView AddLine() function?[/quote]Nope. You have to add it explicitly with AddLine()…
The project that I’m working on has a large amount of coded cout statements that I would like to print out in a text box in my GUI. I’ve attached a macro showing a simple example of code just for clarity’s sake. I’d really prefer to not have to rewrite all the cout statements so is there any other way I can print these statements to a text viewer?
Thanks again. I really appreciate all your help. cout_example.C (166 Bytes)
gSystem->RedirectOutput("test_cout.txt", "a");
cout << "Hello! I'm wondering if there is any other way to print this statement to a text box that I would display in my GUI." << endl;
gSystem->RedirectOutput(0);
fTextView->LoadFile("test_cout.txt");
My apologies. As I kept working on my project, I discovered that I’m still not able to do exactly what I’m hoping for. I would like to redirect the standard output to a view box such that the box updates in real time.
In my project, there are standard output statements in external executables/functions whose code I do not have access to. Because of this, I cannot use AddLine and I cannot Update the view box or reload the file after every cout statement which means I have to wait for the executable/function to complete before I see any output in the TGTextView box. This is a problem because I need to see the cout statements in real time to look for error messages that might arise while running the external executables/functions.
I’m guessing there is no other workaround, correct?
I also saw a project proposal for redirecting standard output to TGTextView. Is there a timeline available for that?
Well, I think there is a misunderstanding here. If you don’t have control of the other application, then I don’t see how you can redirect its stdout… and the project proposal you’re referring to is to redirect ostream to TGTextView (e.g. make a class inheriting from both TGTextView and ostream), and it would not solve the problem with other applications…