Passing a file descriptor
I am trying to right a function which uses a file descriptor to write to a log file. The problem is that the on the print statement the file descriptor is called bad. Now when I first open the file and print to it in the f_open function by passing the descriptor to f_print_log all works well, however when I returned the file descriptor to logtest.sh and then try to pass it to f_print_log I get bad file descriptor. Any help would be appreciated. Here are my functions and calling script:
********* THESE FUNCTIONS ARE IN f_log.sh
function f_open_log
{
next_fh=$LOG_FH_COUNTER
eval "exec $next_fh>$1"
f_print_log $next_fh "Log file opened"
(( LOG_FH_COUNTER=LOG_FH_COUNTER + 1 ))
echo ${next_fh}
return 0
}
function f_print_log
{
print -u$1 $2
return 0
}
***************************************************
logtest.sh -->
#!/bin/ksh
. f_log.sh
typeset -i LOG_FH_COUNTER=3
LOG=$(f_open_log bigfile)
f_print_log $LOG "This is a test"
exit
|