system("top") in a C program giving problems when the C prg is run by cron
i have used something like
system("top -p 3211 -p 3232 -n 1 > log.txt ");
in my c program. The C prgm is running well when i run it from inside a terminal.
I have included the executable of this c program in the crontab file for root.
But it is giving unknown TERM VT100 error then and top command is not run successfully, i.e, no output. So I set $TERM = vt100 and $TERMCAP= the termcap file for vt100
i tried setting $TERM = xterm and $TERM = linux with their corresponding values(paths of terminfo files) in $TERMCAP. But the tcgetattr() fn returned error. Now How can I get this program to work when its executed automatically by cron daemon.
I tried using execl() instead of system() API to execute the top command inside the C program. But I dont know how to write the output of the thus executed top command to a file. Please let me know how to do this.
Please let me know the solution wither way.
Thanks and Regards