# Re: Trying to get a value from cshell script inside ruby

**URL:** <https://www.ruby-forum.com/t/re-trying-to-get-a-value-from-cshell-script-inside-ruby/139797>\
**Category:** Ruby\
**Created:** [June 7, 2008, 4:29am UTC](https://www.ruby-forum.com/t/re-trying-to-get-a-value-from-cshell-script-inside-ruby/139797 "2008-06-07T04:29:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![McLaughlinS\_James\_T](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f04885/32.png) [@McLaughlinS\_James\_T](https://www.ruby-forum.com/u/McLaughlinS_James_T)\
**Post date:** [June 7, 2008, 4:29am UTC](https://www.ruby-forum.com/t/re-trying-to-get-a-value-from-cshell-script-inside-ruby/139797/1 "2008-06-07T04:29:38Z")

</div>

You can use env to get the value of $STAT from ruby. Please forgive me  
if I miss some details here but…

Try this:

puts ENV[“STAT”]

That should print the value of the env variable named STAT. I am not  
sure how changes to the var by a script called by the ruby prog are  
reflected in the current env hash - check the docs there may be an  
env.reload method.  
Jamie McLaughlin  
SAIC  
Office: 703-292-6307  
Mobile: 571-263-2528

----- Original Message -----  
From: removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
To: ruby-talk ML [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Sent: Fri Jun 06 18:51:40 2008  
Subject: Trying to get a value from cshell script inside ruby

I am trying to run the c shell script inside ruby script.  
Looks something like this:

csh\_script = File.new(TemporaryFile.getFileName(“test\_csh”), w)  
csh\_script.puts(“#!/bin/csh/”)  
csh\_script.chmod(0555)  
csh\_script.puts(" ls -l | wc -l") #some command here  
csh\_script.puts(“$STAT = $?”)  
csh\_script.puts(“exit($STAT)”)  
csh\_script.close

#then call smth like this in order to execute the script

system(csh\_script.path)

What I am trying to get is the value of the $STAT to get passed in to  
the ruby script and assigned to some variable

## I would appreciate any help

Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
