# Problem executing bash script from ruby - resend

**URL:** <https://www.ruby-forum.com/t/problem-executing-bash-script-from-ruby-resend/172170>\
**Category:** Ruby\
**Created:** [July 16, 2009, 3:24am UTC](https://www.ruby-forum.com/t/problem-executing-bash-script-from-ruby-resend/172170 "2009-07-16T03:24:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tbcox23](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b9bd4f/32.png) [@tbcox23](https://www.ruby-forum.com/u/tbcox23)\
**Post date:** [July 16, 2009, 3:24am UTC](https://www.ruby-forum.com/t/problem-executing-bash-script-from-ruby-resend/172170/1 "2009-07-16T03:24:06Z")

</div>

[for some reason, my first attempt was not formatted correctly by the  
list server]

I have little experience with this sort of thing, but it looked fairly  
straightforward. I’m in trouble, however.

Details:

From /home/tomc/Ruby-work/setnet/bin/ I launch “./setnet”. This dir  
contains:  
mkrdoc.sh setnet

“./setnet” contains these lines (among others), and works fine:

manager = SN::DBManager.new()  
manager.startup

The “SN.rb” module is in “/home/tomc/Ruby-work/setnet/lib/setnet”, and  
contains a method with this code snippet -

puts “\n=== generating new rdocs for SetNet ===”  
system(“ls”) # to verify where I am in the filesystem  
system("./mkrdoc.sh")  
if $? != 0  
puts “\*\*\* command failed: status = #{$?.exitstatus}”  
end

This snippet executes by means of selection from a menu, with this  
result -

=== generating new rdocs for SetNet ===  
mkrdoc.sh setnet  
\*\*\* command failed: status = 127

mkrdoc.sh contains:

cd …/lib/setnet  
echo “dir–”  
ls  
echo “rdoc executing --”  
rdoc -N -x ./doc

What I’m trying to do is acquire the functionality of generating new  
rdocs for my program without having to manually go back to a command  
line. Every attempt I made to make a single “system()” call from within  
ruby, to generate the rdocs, have failed. In my experience, rdoc is  
excessively quirky. I’ve spent most of today trying to get it to do some  
simple things, and failing, even though I’ve very carefully following  
the documentation. I do have something that works - that “rdoc -N -s  
./doc” command, but only when it’s executed from within the right dir.

Since -

- I’m allowed one command per “system()” call, and
- upon return from that call, the present working dir is reset to its  
prior state…

my only option appears to be to issue the commands I’d use in a manual  
interaction with the CLI from within a script file, and that’s what I’m  
trying to do.

My questions:

1. Is there some obvious reason by my attempt to execute mkrdoc.sh is  
failing?
2. How can I make use of the process status output I’ve captured? I’ve  
searched Pickax 3rd ed., and with Google, and I’m not receiving much  
enlightenment. What do the “big boys/girls” do with this status output?

Thanks very much for any help anyone can offer.

Tom

–

```auto
Tom C., MS MA, LMHC - Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< removed_email_address@domain.invalid >> (email)
<< TomCloyd.com >> (website)
<< sleightmind.wordpress.com >> (mental health weblog)

```

---

<div class="post-metadata">

**Author:** ![tbcox23](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b9bd4f/32.png) [@tbcox23](https://www.ruby-forum.com/u/tbcox23)\
**Post date:** [July 16, 2009, 2:04pm UTC](https://www.ruby-forum.com/t/problem-executing-bash-script-from-ruby-resend/172170/2 "2009-07-16T14:04:26Z")

</div>

On Wed, Jul 15, 2009 at 9:23 PM, Tom C.[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Since -
> 
> - I’m allowed one command per “system()” call, and
> - upon return from that call, the present working dir is reset to its  
> prior state…
> 
> my only option appears to be to issue the commands I’d use in a manual  
> interaction with the CLI from within a script file, and that’s what I’m  
> trying to do.

It is possible to change the working directory from within ruby:

> cd /  
> irb  
> irb(main):001:0\> puts `pwd`  
> /  
> =\> nil  
> irb(main):002:0\> Dir.chdir(“/tmp”) { puts `pwd` }  
> /tmp  
> =\> nil  
> irb(main):003:0\> puts `pwd`  
> /  
> =\> nil  
> irb(main):004:0\> Dir.chdir(“/var/tmp”)  
> =\> 0  
> irb(main):005:0\> puts `pwd`  
> /var/tmp  
> =\> nil

---

<div class="post-metadata">

**Author:** ![tbcox23](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b9bd4f/32.png) [@tbcox23](https://www.ruby-forum.com/u/tbcox23)\
**Post date:** [July 16, 2009, 5:20pm UTC](https://www.ruby-forum.com/t/problem-executing-bash-script-from-ruby-resend/172170/3 "2009-07-16T17:20:58Z")

</div>

Tom C. wrote:

> Since -
> 
> - I’m allowed one command per “system()” call, and

Maybe I didn’t read carefully enough, but where is this  
limit coming from? E.g.,

% ruby -e ‘system %|echo hello && date && echo goodbye|’  
hello  
Thu Jul 16 11:19:03 EDT 2009  
goodbye

Regards,
