LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-01-2007, 12:05 AM   #1
ramesh6056
Member
 
Registered: May 2007
Posts: 89

Rep: Reputation: 15
Redirecting stdout instantaneously...


Hi all,

I am using text to speech program to read a text file..

As soon as i execute the command

flite -pw alice.txt

It speak out the alice.txt file and simultaneously prints the text which was read...Now i want this text i.e, the text printed on stdout to be redirected to a file..

This can be done easily with redirection...but my problem is, since alice.txt is big it takes long time to speak out and read it...only after completion of this process i am able to redirect it to a file...i want to read the stdout instantaneously and write it into a file...(while flite is writing to stdout at the same time i want to read and write it in to file)

I tried popen, redirection command..nothing was useful..

All comments are welcome...
 
Old 09-01-2007, 12:51 AM   #2
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141

Rep: Reputation: 168Reputation: 168
Have you used the tee command? It allows you to send output to a file at the same time as stdout.
 
Old 09-02-2007, 11:05 PM   #3
ramesh6056
Member
 
Registered: May 2007
Posts: 89

Original Poster
Rep: Reputation: 15
Arrow

Hi,

Thanks for your reply,but the tee command just redirects the stdinput to the stdoutput or to a file...

I tried running the command "tee stdoutput.txt" as a child process and made parent to execute the command "flite -pw alice.txt"

When the parent was executing the flite command, it prints the alice.txt line by line to stdoutput..

But the tee command by the child is not capturing the stdoutput to stdoutput.txt

Any other way of writing the program???
Any other commands??

Last edited by ramesh6056; 09-02-2007 at 11:08 PM.
 
Old 09-03-2007, 07:41 AM   #4
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 234Reputation: 234Reputation: 234
Please show your actual code -- it sounds to me as if you aren't using tee correctly.
 
Old 09-03-2007, 11:38 PM   #5
ramesh6056
Member
 
Registered: May 2007
Posts: 89

Original Poster
Rep: Reputation: 15
Thanks for your reply...This is the program that i used to test the tee command...

#include <stdio.h>
int main()
{
int pid;
pid =fork();
if (pid ==0) //Executed by the child process
{
printf("\nChild process activated\n");
system("tee stdoutput.txt");
}
else //Executed by the parent process
{
printf("\nParent process activated\n");
system("flite -pw alice");
}
}
 
Old 09-03-2007, 11:59 PM   #6
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141

Rep: Reputation: 168Reputation: 168
The tee command is better used at the shell level rather than being called from your application. The following will display the flite's normal output on stdout as well as writing it to stdoutput.txt:
Code:
flite -pw alice.txt | tee stdoutput.txt
 
Old 09-04-2007, 12:54 AM   #7
ramesh6056
Member
 
Registered: May 2007
Posts: 89

Original Poster
Rep: Reputation: 15
Hi, thanks for your reply..

I tried your command.

flite -pw alice.txt | tee stdoutput.txt

I executed the above command in one terminal and opened another terminal where i opened stdoutput.txt...

vi stdoutput.txt

I am not able to see the output...

What happens is, only after completing the command flite -pw alice.txt, that is only after reading the entire file alice.txt and printing into stdout, the stdout is transferred to stdoutput.txt...

It is not like printing the output to stdoutput as well as to stdoutput.txt at the sametime...But i want the my stdoutput.txt to reflect changes at the same time when stdoutput is changing...the change should be instantaneous...

Is there any way??
 
Old 09-04-2007, 01:57 AM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,362

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
In the 2nd terminal, use
tail -f stdoutput.txt
which should be better, but note there is always a certain amt of buffering going on in the background by the OS.
Incidentally, why 'instantaneously'? What's the rush?
 
Old 10-04-2007, 11:15 AM   #9
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 234Reputation: 234Reputation: 234
Did the last suggestion work?

Your answer could be helpful to others w/ the same problem.
 
  


Reply



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
Redirecting stdout, stderr to pty0? Rostfrei Linux - General 4 03-20-2007 03:15 AM
redirecting stdout to /dev/null and stderr to stdout? Thinking Programming 1 05-18-2006 02:36 AM
Redirecting to file and stdout Quantum0726 Programming 3 11-14-2005 08:35 PM
redirecting stdout and stderr to a file Avatar33 Programming 4 03-12-2005 07:55 AM
Redirecting stdout to tar hari_s_82 Linux - Newbie 6 10-08-2004 01:49 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:06 PM.

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