Print C file output both in stdout and file


 
Thread Tools Search this Thread
Top Forums Programming Print C file output both in stdout and file
# 1  
Old 11-12-2008
Print C file output both in stdout and file

Hello! I want to post a question. does anybody know how to print the output of a C program both in stdout and a file??
thanx
# 2  
Old 11-12-2008
Code:
myCprogram | tee -a myCprogram.log

# 3  
Old 11-12-2008
Quote:
Originally Posted by jim mcnamara
Code:
myCprogram | tee -a myCprogram.log

Thanx! but i want to do that using C commands. Neither unix or system("tee...")
# 4  
Old 11-12-2008
Use fopen() then fprintf() for output to a file or stdout.
# 5  
Old 11-13-2008
i think you can use fopen() and fprintf() to write to the file, then you use printf() to display...
# 6  
Old 11-13-2008
fprintf() can write to both the file and the display which is associated with file stdout.
# 7  
Old 11-13-2008
execve-stdout and file

I wrote down this code in C,

....
pid=fork()
if (pid==0)
{execve("..program to execute",NULL,NULL);exit(1);}
else if(pid>0)
{printf("parent");}
else
{perror("error");}

I want to print the result of execve sys call (the output of the program), both in stdout and in a file without the need to execute it twice?
thanxSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Output of until to file versus stdout

Why does this until false; do history | head -5; done result in a stdout infinite loop, yet until false; do history | head -5 > hist5; done only writes it once to file hist5? Furthermore, I can hear the hard drive working on the 2nd command until I end the process, but the history | head -5 is... (1 Reply)
Discussion started by: Xubuntu56
1 Replies

2. Shell Programming and Scripting

Print the output with different file names

I have a python script that gives output called test.png. By using the following command I run the script every 2 seconds. What is the easiest way to save the output as follows ( test.png (1st output), tes1.png (second output), tes2.png ....) Command I i use while sleep 2; do python... (1 Reply)
Discussion started by: quincyjones
1 Replies

3. Shell Programming and Scripting

Run a program-print parameters to output file-replace op file contents with max 4th col

Hi Friends, This is the only solution to my task. So, any help is highly appreciated. I have a file cat input1.bed chr1 100 200 abc chr1 120 300 def chr1 145 226 ghi chr2 567 600 unix Now, I have another file by name input2.bed (This file is a binary file not readable by the... (7 Replies)
Discussion started by: jacobs.smith
7 Replies

4. Shell Programming and Scripting

File descriptors, redirecting output, and stdout

Hello all. I've been lurking here for a year or two and finally decided to post. I need some assistance with file descriptors, stdout, and redirecting output. I've searched through a number of very helpful threads here (unfortunately I can't link to any of them yet due to my low post count...),... (2 Replies)
Discussion started by: Michael_K
2 Replies

5. Shell Programming and Scripting

Awk script to run a sql and print the output to an output file

Hi All, I have around 900 Select Sql's which I would like to run in an awk script and print the output of those sql's in an txt file. Can you anyone pls let me know how do I do it and execute the awk script? Thanks. (4 Replies)
Discussion started by: adept
4 Replies

6. Shell Programming and Scripting

Print to both file and stdout

Using echo command, send output to both places. I think I knew this but forgot. Thanks in advance (2 Replies)
Discussion started by: stevensw
2 Replies

7. Shell Programming and Scripting

Print permissions for a file in output

hi i m trying to print the permissions for a file in output echo name read name touch name.txt permission=$((ls -l $name.txt)) echo permission please suggest where i went wrong? (2 Replies)
Discussion started by: angel12345
2 Replies

8. Shell Programming and Scripting

print out a line from a output file

I am trying to have a script ping all the clients then output it to a file so I know which clients are off then have the next script pull the ones that are online and reboot them. This is what I am running with right now. If there is something KISS then by all means please let me know. ... (3 Replies)
Discussion started by: deaconf19
3 Replies

9. Shell Programming and Scripting

let curl output to stdout AND save to a file

hello hackers. i have a curl process running as cgi directly pushing stdout to the client. but i want to additionally save that stream to a file at the same time. any directions madly welcome. thanks in advance (3 Replies)
Discussion started by: scarfake
3 Replies

10. Shell Programming and Scripting

Dual output (stdout and file)

Hello everybody, Is there a more elegant way to make dual output (display on standard output and append to a file) while I'm executing a shell script, besides duplicating the echo command for every string? echo "Message..." > 1 echo "Message..." >> myfile.out Thank you for your time,... (2 Replies)
Discussion started by: AdrianM
2 Replies
Login or Register to Ask a Question