[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

system() and changing (path-)environment

Karl Voit

10/6/2006 7:56:00 AM

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?

--
Karl Voit
3 Answers

Jim Crossley

10/6/2006 11:40:00 AM

0

Hi...

Karl Voit <devnull@Karl-Voit.at> 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

Tim Hunter

10/6/2006 11:44:00 AM

0

Karl Voit wrote:
> 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?
>
>
You can use Dir.chdir to temporarily change the current directory:

Dir.chdir('path2') do
system('shellscript.ksh')
end

After the block the current directory returns to its former state.


Karl Voit

10/9/2006 6:01:00 AM

0

* Timothy Hunter <TimHunter@nc.rr.com> wrote:
>
> You can use Dir.chdir to temporarily change the current directory:
>
> Dir.chdir('path2') do
> system('shellscript.ksh')
> end
>
> After the block the current directory returns to its former state.

Thanks for the hint! I did not knew the class Dir before!

--
Karl Voit
http://www.Karl-Voit.at/scripts/#b...