DaemonForums  

Go Back   DaemonForums > Miscellaneous > Programming

Programming C, bash, Python, Perl, PHP, Java, you name it.

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #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
Thanked 112 Times in 104 Posts
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, 22 views)
File Type: c snip.c (538 Bytes, 23 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
 

Tags
/dev/fd/3

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Uncompatable BSD programs and drivers oscurochu FreeBSD General 11 25th August 2009 06:22 PM
Distributed Computing Programs JMJ_coder General software and network 0 25th November 2008 08:50 PM
Passing args to port / make while installing apache robot FreeBSD Ports and Packages 2 27th August 2008 01:55 PM
passing arg from bootloadder to kernel l2fl2f FreeBSD General 16 15th May 2008 12:38 PM
Programs syrushcw FreeBSD Security 1 2nd May 2008 05:44 PM


All times are GMT. The time now is 07:52 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick