Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 08-22-2009, 07:02 AM   #1
Registered: Jul 2009
Posts: 42

Rep: Reputation: 16
Question How to create a log file for a program


I have written a C program, where i am calling some scripts.
I want to log all the data which is displayed on terminal at the time of program execution.

I tried using system("script log.out")but unable to log the data.
after exiting script command program execution is starting.
Help me.

Old 08-22-2009, 09:41 AM   #2
Senior Member
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,994

Rep: Reputation: 76
The script command starts a new login process to capture terminal input and output, so the rest of your program won't run until it's completed.

You can do this in one of two ways: you could use script, but have it shell back to your program:
script -c '/path/to/program args'
Alternatively, if all you want to do is to capture the output of the program, you can reopen standard output (and/or standard error) like this:
freopen("log.out", "w+", stdout);
You might also look to using /dev/tty to get the actual terminal I/O if you're already doing stream redirection on stdout.

Hope that helps,

—Robert J Lee


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create log file from script fotoguy Programming 12 03-27-2012 07:39 AM
Create log file against a script shipon_97 Linux - Newbie 1 01-02-2008 12:54 PM
How to create a log File using tee?? rmvinodh123 Programming 1 04-12-2007 03:21 AM
need to create log file sanjay2004 Linux - Newbie 6 02-27-2006 12:11 PM
Script to create a log file satimis Programming 15 01-16-2006 07:39 AM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:09 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration