Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

output redirection produces empty file [duplicate]

Tags:

c

linux

bash

So this is probably a stupid question, but I can't see what I'm doing wrong.

I am running a program that produces output when called like ./ar. The output looks like:

-0.00781 0.02344 0.98828                                                        
-0.01172 0.02734 0.98828                                                        
-0.01562 0.02344 0.98047                                                        
-0.00781 0.02344 1.00000                                                        
-0.00391 0.02344 0.98438 

A new line of output is written every second.

When I call the code like this ./ar > log and kill the program using ctrl-c after a few seconds, the file log is empty.

I am running this code on an embedded system. The system has a writeable partition which is the partition that I am running in, and I have write access as I am logged in as root.

like image 929
James Avatar asked May 23 '13 13:05

James


2 Answers

The reason is the lazy writing concept of UNIX system.

like image 67
Anand Shah Avatar answered Sep 23 '22 01:09

Anand Shah


Are you sure you are looking at standard output in you call ./ar? It might be standard error. So, try ./ar >log 2>err to have 2 files, one for stdout and one for stderr.

Or use ./ar 2>&1 >log to get one file for both streams.

like image 32
Frank Avatar answered Sep 21 '22 01:09

Frank