Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Capture screen output

Status
Not open for further replies.
Feb 12, 2002
80
0
0
NO
Unsure if this is the right forum, but I already tried UNIX and got no-where, hoping this give me more ...

I have a .c program I am running on Solaris.

As the program runs, it writes text out to the terminal window. I want to capture this text in a log file so that other users can tail -f the log file and see what is happening.

I have had a loko atthe source code and can see that the text is written out using printf("text");

I have tried the following:

Code:
script
program
This does not output anytihng until the program ends, so no use. The -f (flush) option is not valid on our system (SunOS 5.8).

Code:
program | tee -a file.log
The program does not run

Code:
prgram > file.log
I tried all sorts of variations including 2>&1 etc - again, the program does not run.

I do not want to share my terminal window using netmeeting or anything similar.

Any other ideas?

I assume I could edit the program to write out to a log file, but I don't really want to have to do that - it's a delicate (read: flakey/shoddy) program and I don't want to start tinkering with it.

Cheers.
 
Code:
./program > file.log
This should always work.
Does file.log get created when you do this? If it does, is it empty?

Do other things exhibit the same behavior? Ex.
Code:
ls -al > dir.txt
 
Thanks for the reply.

when I try redirection like that - or even the full file path of the compiled program, the log file is created but stays empty - and the program does not seem to run.

Yes - redirection works normally for everything else.
 
> and can see that the text is written out using printf("text");
But is any of it followed with a newline?
Say
[tt]printf("text\n");[/tt]
Text which is unflushed may remain in a buffer a lot longer if the stdout has been redirected in some way.

I've just tried a noddy program, and 'script' works just as one would expect it to.
Code:
$ cat foo.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main()
{
    int i;
    for ( i = 0 ; i < 10 ; i++ ) {
        printf("%d ", i );
        if ( i % 2 == 0 ) {
            sleep(1);
        } else {
            printf("\n");
        }
    }
    return 0;
}

$ gcc foo.c
$ script -f xF2.txt
Script started, file is xF2.txt
$ ./a.exe
0 1
2 3
4 5
6 7
8 9
$ exit
exit
Script done, file is xF2.txt
$ cat xF2.txt
Script started on Thu May 24 18:14:10 2007
$ ./a.exe
0 1
2 3
4 5
6 7
8 9
$ exit
exit

Script done on Thu May 24 18:14:24 2007
The numbers duly appeared spaced by a second (not all in a rush at the end).

> it's a delicate (read: flakey/shoddy) program and I don't want to start tinkering with it.
That could be the problem in itself. I have seen on one occasion in the dim and distant past an example of a program which actually crashed whenever I tried to redirect it.


--
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
 
Thanks for the help everyone.

I have found that the script does in deed output to a log file upon redirection - but only after 10 minutes or so - I assume it is filing a buffer and only puging once the buffer is full.

However this is probably good enough for our needs at the moment.

I think the true solution is gonig to be arrange for the .c program to output to a log file as well as to screen - it was written with the intention of being used by a single user. Now we have multiple users it just doesn;t come up to standard ..

thansk for the input everyone.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top