LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   PerlTK - save console in file (http://www.linuxquestions.org/questions/programming-9/perltk-save-console-in-file-510113/)

Rufus T. Firefly 12-13-2006 02:26 PM

PerlTK - save console in file
 
I'm running perl 5.8.8 on Fedora Core 5.

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.

Any help would be appreciated.

chrism01 12-13-2006 05:47 PM

Sounds like the C progs are opening a separate filehandle to the console and printing to that.
Do you have access to the src?

puffinman 12-13-2006 06:12 PM

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).

chrism01 12-13-2006 07:40 PM

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.

puffinman 12-13-2006 08:08 PM

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).

chrism01 12-13-2006 08:16 PM

If he doesn't have the src code, the screen cmd should help: http://www.oreillynet.com/linux/cmd/...?path=s/screen

Rufus T. Firefly 12-13-2006 09:42 PM

Quote:

Originally Posted by chrism01
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.

Thank You for the response.

Rufus T. Firefly 12-13-2006 09:48 PM

Quote:

Originally Posted by chrism01
If he doesn't have the src code, the screen cmd should help: http://www.oreillynet.com/linux/cmd/...?path=s/screen

That's a good link on terminals ... thanks.


All times are GMT -5. The time now is 11:23 PM.