Sponsored Content
Full Discussion: Passing a file descriptor
Top Forums Shell Programming and Scripting Passing a file descriptor Post 302202391 by robotball on Wednesday 4th of June 2008 05:48:35 PM
Old 06-04-2008
Question 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
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

bad file descriptor?

Ok, I'm sure this is a total newbie question, but I think I'm in the right place, no? I'm trying to call a perl module from a cgi script - Mail::Sendmail - and my web host installed the module in a directory that doesn't seem to be accessible, at least not the way I'm trying. But I thought you... (1 Reply)
Discussion started by: ftb
1 Replies

2. UNIX for Dummies Questions & Answers

file activity (open/closed) file descriptor info using KORN shell scripting

I am trying to find a way to check the current status of a file. Such as some cron job processes are dependent on the completion of others. if a file is currently being accessed / modified or simply open state I will wait until it is done being processed before attempting the next process on that... (3 Replies)
Discussion started by: Gary Dunn
3 Replies

3. UNIX for Dummies Questions & Answers

File Descriptor Help

What is a file descriptor in Unix?? How to find a file descriptor of a file in Unix?? Does it have anything to do with the Inode numbers?? (3 Replies)
Discussion started by: rahulrathod
3 Replies

4. Programming

Problems with file descriptor

Hi, look at the following code: The client after estabilishing a connection with the server does the following: if ((peter = fopen(argv, "r")) == NULL){ printf("errore\n"); exit(0); } ... (11 Replies)
Discussion started by: teo
11 Replies

5. Programming

File descriptor constant

I have a requirement to close all the file descriptors from 3 to 1024 for a particular application. Right now, this is how I do it .. for ( int i = 3 ; i <= 1024; ++i ) close(i); The change I am looking at is, I want to do away with the number 1024 and replace it with a constant which... (4 Replies)
Discussion started by: vino
4 Replies

6. UNIX for Advanced & Expert Users

File Descriptor Table

Im working on writing a small operating system. I am currently working on implementing dup, dup2, pipe, and close and I need to implement some type of file descriptor table in my PCB. I was wondering if there is anyone who is familiar with linux/unix implementation of these tables who could... (6 Replies)
Discussion started by: Ashaman0
6 Replies

7. Shell Programming and Scripting

File Descriptor

Hello All, Im opening a file desciptor in perl and sending data using print CMD "$xyz". is there a limit to the length of the string that I can give to this CMD at a time. (3 Replies)
Discussion started by: rimser9
3 Replies

8. UNIX for Dummies Questions & Answers

File Descriptor

Hi What the below path contains? /proc/<pid>/fd (1 Reply)
Discussion started by: siba.s.nayak
1 Replies

9. Shell Programming and Scripting

file descriptor count

I am trying to write a script which will only show me the file descriptor count for a process/pid. My script will return me the count only not the whole output. For example, I would like my script to return the output 23 this case, not the whole output. Can anybody please help me how do I get... (11 Replies)
Discussion started by: mohullah
11 Replies

10. Shell Programming and Scripting

Variable File Descriptor

Greetings. I am happily using constructs like the following; I have set -x to show fine distinctions. $ exec 4> afile + exec + 4> afile $ print -u4 This is the first line in afileAs you can see from the -x expansion, the shell performed the exec command and redirected file descriptor to... (4 Replies)
Discussion started by: rpaskudniak
4 Replies
dirfd(3C)						   Standard C Library Functions 						 dirfd(3C)

NAME
dirfd - get directory stream file descriptor SYNOPSIS
#include <dirent.h> int dirfd(DIR *dir); DESCRIPTION
The dirfd() function returns the file descriptor associated with the directory stream dir. This file descriptor is the one used internally by the directory stream operations. See opendir(3C), closedir(3C), readdir(3C), rewind- dir(3C), seekdir(3C), telldir(3C). The file descriptor is automatically closed when closedir() is called for the directory stream dir or when one of the exec functions is called. See exec(2). The file descriptor can safely be used only by functions that do not depend on or alter the file position, such as fstat(2) and fchdir(2). Closing the file descriptor with close(2) or modifying the file position by means other than the directory stream operations listed above causes undefined behavior to occur when one of the directory stream operations is subsequently called with the directory stream dir. RETURN VALUES
Upon successful completion, the dirfd() function returns an open file descriptor for the directory associated with the directory stream dir. ERRORS
There are no defined error returns. Passing an invalid directory stream as an argument to the dirfd() function results in undefined behav- ior. USAGE
The dirfd() function is intended to be used to obtain a file descriptor for use with the fchdir() function. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Committed | +-----------------------------+-----------------------------+ |MT-Level |Safe | +-----------------------------+-----------------------------+ SEE ALSO
close(2), exec(2), fchdir(2), fstat(2), closedir(3C), opendir(3C), readdir(3C), rewinddir(3C), seekdir(3C), telldir(3C), attributes(5) SunOS 5.11 24 Oct 2007 dirfd(3C)
All times are GMT -4. The time now is 04:14 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy