View Single Post
  #1   (View Single Post)  
Old 28th March 2009
TerryP's Avatar
TerryP TerryP is offline
Arp Constable
 
Join Date: May 2008
Location: USofA
Posts: 1,547
Default problem passing /dev/fd/n to programs

I have a perl script that needs to invoke an editor on a temporary file, which is created with File::Temp::tempfile(). What I would like to do, is have it check if there is an accessible /dev/fd or /proc/$$/fd directory on the system: and if so pass the file descriptor to the editor through the file system instead of using the file name; if there is no such directory, bite the bullet and use the filename. I've tried cat, ed, vi, and vim but none seem to work via "/dev/fd/".fileno($fh) here. Then I wrote a small C program that opens a test file, clears the close on exec flag, concatenates the editor, /dev/fd, and the fileno() into a single string, passes it on to system(). For quick testing I set the editor to use as "cat".


On FreeBSD 7, I get '/dev/fd/3: No such file or directory' when attempting to open the file, on OpenBSD 4.4 I get successful access to the temporary file through /dev/fd/.fileno; but on FreeBSD it refuses!


I might very well be an idiot, but I don't get it. Does FreeBSD not create /dev/fd/n's greater then the 0,1,2 std{out,in,err} files for a program by default or something?



attachments if wanted: snip.pl the portion of perl code, snip.c the super quick c code.
Attached Files
File Type: pl snip.pl (801 Bytes, 86 views)
File Type: c snip.c (538 Bytes, 82 views)
__________________
My Journal

Thou shalt check the array bounds of all strings (indeed, all arrays), for surely where thou typest ``foo'' someone someday shall type ``supercalifragilisticexpialidocious''.

Last edited by TerryP; 31st March 2009 at 06:16 AM.
Reply With Quote