Solved

Problems with redirection

Posted on 2002-07-23
9
196 Views
Last Modified: 2010-04-21
I have this comand

xxx > file.txt

after that there many persons doing something like

tail -f file.txt


My problem is that the command sends litle messages and is not imediatly write to the file. There is any way to redirection imediatly write to the text file the output of the command.

I don't have admin premictions.
0
Comment
Question by:oleber
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 14

Expert Comment

by:chris_calabrese
ID: 7172022
The problem is likly that the xxx program uses the C stdio library, which knows the data is going to a file and buffers it.

Try
xxx | cat > file.txt
0
 
LVL 10

Author Comment

by:oleber
ID: 7172079
I'm using this code

perl -e 'for ($i=0; $i<100000; $i++) {print "$i\n";if ($i % 1000 == 0){sleep 1}}' | cat > lixo.txt & ; tail -f lixo.txt

So just must stop if $i end's on 000, it stops in diferent values



My unix version

> version
Machine hardware:   sun4u
OS version:         5.6
Processor type:     sparc
Hardware:           SUNW,Ultra-4

...
0
 
LVL 14

Expert Comment

by:chris_calabrese
ID: 7172113
How busy is the machine? Maybe the job just isn't running continuously. Try a bigger sleep so you can tell the difference between machine business and intentional sleeps.

If this is buffering problem, you'll see things like the output being cut in the middle of a line.
0
 
LVL 10

Author Comment

by:oleber
ID: 7172120
It's what is happening. The numbers are beeing cut in the middle of a line.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 51

Expert Comment

by:ahoffmann
ID: 7172199
perl -e '$|=1;for ($i=0; $i<100000; $i++){print "$i\n";if ($i % 1000 == 0){sleep 1}}' | cat > lixo.txt & ; tail -f lixo.txt
0
 
LVL 10

Author Comment

by:oleber
ID: 7172217
sorry, i full you with the code
perl -e '$|=1;for ($i=0; $i<100000; $i++){print "$i\n";if ($i % 1000 == 0){sleep 1}}'

What I have is a C/C++ program, the perl just sorce was an example of a command.

please, is there a way of doing something similar to $|=1 in C/C++.
0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 50 total points
ID: 7172351
fflush()
0
 
LVL 14

Expert Comment

by:chris_calabrese
ID: 7172747
and/or setbuf()
0
 
LVL 20

Expert Comment

by:tfewster
ID: 7921664
No comment has been added lately, so it's time to clean up this Topic Area.
I will leave a recommendation for this question in the Cleanup topic area as follows:

- PAQ, no points refunded

Please leave any comments here within the next 7 days

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

tfewster
Cleanup Volunteer
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now