Solved

Problems with redirection

Posted on 2002-07-23
9
198 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to find files recursively in ftp server quickly? 7 124
Bad Block Relocation for Synchronous GLVM AIX 7.1 2 76
AIX 5.x set up arrow to recall 11 58
centos commands 6 69
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
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.:

830 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