# Load "/proc/self/fd/#{$stdin.fileno}"

**URL:** <https://www.ruby-forum.com/t/load-proc-self-fd-stdin-fileno/165886>\
**Category:** Ruby\
**Created:** [April 19, 2009, 2:00am UTC](https://www.ruby-forum.com/t/load-proc-self-fd-stdin-fileno/165886 "2009-04-19T02:00:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![samoht](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ac8455/32.png) [@samoht](https://www.ruby-forum.com/u/samoht)\
**Post date:** [April 19, 2009, 2:00am UTC](https://www.ruby-forum.com/t/load-proc-self-fd-stdin-fileno/165886/1 "2009-04-19T02:00:39Z")

</div>

Hello,

the Ruby code in this article’s subject works for my machine running  
Ubuntu Linux, but I don’t expect it to work for different operating  
systems (NetBSD, FreeBSD a.s.o.).

How can alternative OS independent Ruby code look like? Of course, it  
shall also load from standard input rather than from a file. Despite  
that, it shall be very close to loading a “real” file, e.g.: the line  
number of the error location shall be told in case of a syntax error  
within the loaded code.

Regards  
Thomas

---

<div class="post-metadata">

**Author:** ![samoht](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ac8455/32.png) [@samoht](https://www.ruby-forum.com/u/samoht)\
**Post date:** [April 19, 2009, 2:40am UTC](https://www.ruby-forum.com/t/load-proc-self-fd-stdin-fileno/165886/2 "2009-04-19T02:40:25Z")

</div>

On Sat, Apr 18, 2009 at 7:00 PM, Thomas H.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> within the loaded code.  
> $ cat foo.rb  
> eval $stdin.read  
> $ echo "puts ‘this is great’ "| ruby ./foo.rb  
> this is great

---

<div class="post-metadata">

**Author:** ![samoht](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ac8455/32.png) [@samoht](https://www.ruby-forum.com/u/samoht)\
**Post date:** [April 20, 2009, 9:33pm UTC](https://www.ruby-forum.com/t/load-proc-self-fd-stdin-fileno/165886/3 "2009-04-20T21:33:33Z")

</div>

Thomas H. wrote:

> within the loaded code.  
> Use #read and #eval instead of #load, and supply the file/line params to  
> eval:

$ cat bar.rb  
puts “in bar”

xfndksnf\_syntax\_error  
$ cat foo.rb  
file = “bar.rb”

data = File.read(file)

eval data, nil, “your text here”, 0

$ ruby foo.rb  
in bar  
your text here:2: undefined local variable or method  
`xfndksnf\_syntax\_error’ for main:Object (NameError)

---

<div class="post-metadata">

**Author:** ![samoht](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ac8455/32.png) [@samoht](https://www.ruby-forum.com/u/samoht)\
**Post date:** [April 23, 2009, 12:11am UTC](https://www.ruby-forum.com/t/load-proc-self-fd-stdin-fileno/165886/4 "2009-04-23T00:11:00Z")

</div>

Thanks to David and Joel!

Regards  
Thomas
