01-23-04 10:32 PM
parikhk@hotmail.com (Kalpesh Parikh) writes:
quote:
> I am executing a "C" program from my shell script. I am not able to
> capture output from my "C" program into the log file name in my
> script. Here is an example :
>
>
> /* ---------------------- a.c program */
> #incldue <stdio.h>
> #incldue <sys/file.h>
>
> main()
> {
>
> FILE *fp;
>
> if (( fp = fopen ("a.log", "w" )) ! = NULL ){
>
> fprintf(fp, "Hello World \n");
> fclose (fp);
>
> }
>
> }
>
> /* End of a.c program */
> ## then I compiled above a.c program which generated a.out
>
> ## Beginning of my.ksh script
>
> #!/bin/ksh
>
> rm -f a.log
>
> ./a.out | tee -a my.log
>
> ls a.log my.log
>
> # End of my.ksh script
>
>
> Note: a.c and my.ksh files are in same directory.
>
> I see that "Hello World" is printed in a.log file but not in my.log
> file.
>
> How do I get "Hello World" printed in my.log file as well ? (Current
> my.log file has zero bytes after I ran my.ksh.
The tee command takes the standard output of a.out, displays it on the
screen, and writes it to the file my.log. The problem is that a.c
doesn't generate anything on standard output, it only writes directly
to the file. Add a line that calls printf() as well.
Joe
[ Post a follow-up to this message ]
|