# System() and changing (path-)environment

**URL:** <https://www.ruby-forum.com/t/system-and-changing-path-environment/71233>\
**Category:** Ruby\
**Created:** [October 6, 2006, 10:00am UTC](https://www.ruby-forum.com/t/system-and-changing-path-environment/71233 "2006-10-06T10:00:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Karl\_V](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/7c8e57/32.png) [@Karl\_V](https://www.ruby-forum.com/u/Karl_V)\
**Post date:** [October 6, 2006, 10:00am UTC](https://www.ruby-forum.com/t/system-and-changing-path-environment/71233/1 "2006-10-06T10:00:49Z")

</div>

Hi!

I want to replace some shellscripts using ruby and therefore I need a  
method to execute external scripts (ksh). Without rewriting a lot of  
scripts, I need the possibility to execute external scripts in another  
directory (as the ruby-script) but within their directory context:

path1 -\> rubyscript.rb  
module.rb

path2 -\> shellscript.ksh  
anotherscript.ksh  
path3 -\> last\_script.ksh  
found\_another\_one.pl

shellscript.ksh calls the other scripts using relative path statements  
but when I use system(“path2/shellscript.ksh”), shellscript.ksh is  
started with the rubyscript.rb-directory context and within  
shellscript.ksh, the call of “./anotherscript.ksh” or  
“path3/last\_script.ksh” results in “script not found here you fool!”.

I tried some things like  
system(“cd path2; shellscript.ksh”)  
system(“ENVIRONMENTVARIABLE=something shellscript.ksh”)  
but none of them worked out.

What do you suggest?

---

<div class="post-metadata">

**Author:** ![Karl\_V](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/7c8e57/32.png) [@Karl\_V](https://www.ruby-forum.com/u/Karl_V)\
**Post date:** [October 6, 2006, 1:43pm UTC](https://www.ruby-forum.com/t/system-and-changing-path-environment/71233/2 "2006-10-06T13:43:13Z")

</div>

Hi…

Karl V. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

[…]

> shellscript.ksh calls the other scripts using relative path  
> statements but when I use system(“path2/shellscript.ksh”),  
> shellscript.ksh is started with the rubyscript.rb-directory context  
> and within shellscript.ksh, the call of “./anotherscript.ksh” or  
> “path3/last\_script.ksh” results in “script not found here you  
> fool!”.

[…]

> What do you suggest?

Try Dir.chdir(path) prior to the system calls, maybe?

Jim
