LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 08-22-2009, 06:02 AM   #1
laginagesh
Member
 
Registered: Jul 2009
Posts: 42

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


Hi,

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.

Cheers
Nagesh
 
Old 08-22-2009, 08:41 AM   #2
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,991

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


Reply


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 06:39 AM
Create log file against a script shipon_97 Linux - Newbie 1 01-02-2008 11:54 AM
How to create a log File using tee?? rmvinodh123 Programming 1 04-12-2007 02:21 AM
need to create log file sanjay2004 Linux - Newbie 6 02-27-2006 11:11 AM
Script to create a log file satimis Programming 15 01-16-2006 06:39 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:15 PM.

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