LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-13-2006, 01:26 PM   #1
Rufus T. Firefly
LQ Newbie
 
Registered: Feb 2006
Location: Hermosa CA
Distribution: Fedora
Posts: 8

Rep: Reputation: 0
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.
 
Old 12-13-2006, 04:47 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Sounds like the C progs are opening a separate filehandle to the console and printing to that.
Do you have access to the src?
 
Old 12-13-2006, 05:12 PM   #3
puffinman
Member
 
Registered: Jan 2005
Location: Atlanta, GA
Distribution: Gentoo, Slackware
Posts: 217

Rep: Reputation: 31
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).
 
Old 12-13-2006, 06:40 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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.
 
Old 12-13-2006, 07:08 PM   #5
puffinman
Member
 
Registered: Jan 2005
Location: Atlanta, GA
Distribution: Gentoo, Slackware
Posts: 217

Rep: Reputation: 31
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).
 
Old 12-13-2006, 07:16 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
If he doesn't have the src code, the screen cmd should help: http://www.oreillynet.com/linux/cmd/...?path=s/screen
 
Old 12-13-2006, 08:42 PM   #7
Rufus T. Firefly
LQ Newbie
 
Registered: Feb 2006
Location: Hermosa CA
Distribution: Fedora
Posts: 8

Original Poster
Rep: Reputation: 0
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.
 
Old 12-13-2006, 08:48 PM   #8
Rufus T. Firefly
LQ Newbie
 
Registered: Feb 2006
Location: Hermosa CA
Distribution: Fedora
Posts: 8

Original Poster
Rep: Reputation: 0
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.
 
  


Reply

Tags
bash, console, terminal



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
PerlTK loose control in loop Atrocity Programming 1 05-10-2005 12:16 PM
PerlTk package juris Mandriva 0 10-26-2004 04:36 AM
save file as root from x console? rockets Linux - Newbie 5 10-25-2004 08:27 AM
set perlTK always-on-top \ topmost plast1cfl00r Programming 0 08-21-2004 02:24 PM
Mozilla 1.7 - No File Save / File Open dialogs on Slackware 10.0 jayseye Slackware 8 08-10-2004 05:52 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:08 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration