Solved

Problems with redirection

Posted on 2002-07-23
9
195 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

747 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

11 Experts available now in Live!

Get 1:1 Help Now