ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
My program is perlTK that allows the user to select an input file (text) and then it kicks off a series of 'C' programs that translate the input file to what is called 'ARPA' format. The program runs just fine but now I need to add some additional functionality ...
While the 'C' progs are running, they splash some progress (or failure) lines to the perl console (Gnome Terminal). I would like to save these progress lines in a file either real-time as they are being created or by somekind of copy-paste operation from the console to a file.
So far I tried standard redirect (>), STDOUT/STDERR (1>&2) maneuvers, Tk-ExecuteCommand and some other approaches I found in the user groups forums ... all to no avail as they all give me the full outputs of the 'C' programs which I already have. All I need to capture is the console text.
To be honest, I'm not even sure if this is a Perl problem, A TK problem, Bash problem or whatever.
You can redirect stdout (aka the console output) to a file from within perl. See this page for information on using the open function to do this (the relevant part is about half way down the page).
If I understand the OP correctly, looks like he's already (effectively) tried that. It sounds like (?) the console progress output is via a separate dedicated filehandle, hence my qn.
Hmm, you may be right. If there are several programs all writing simultaneously, perhaps the best way would be to create a socket that all the programs can write to, a socket that is being monitored by the main program, which can then redirect all the output to one file (or wherever).
Sounds like the C progs are opening a separate filehandle to the console and printing to that.
Do you have access to the src?
Yes, I have access to the C source code. ALthough it is part of a dedicated 3rd-party toolkit, there is no harm in massaging the code to turn off the current output and write additional code to open an I/O stream to the file I need.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.