External prog get file from main dir, want file in diff dir

External prog get file from main dir, want file in diff dir

Post by Kga Ag » Sat, 27 Jun 2009 20:36:26



I am running a external program(2) from another ruby program (1). This
external program requre a local file (the file must lay in the prog 1
dir) . It uses some kind of custom get comand to get this file.

Say my dir is calld TestCase

Then this fle must be in TesCase/file.txt


But i want to store the file in TestCase/CaseX/file.txt (or in some
other folder)


The problem is that i cant change the extern program, and it asks for
the file to be in TestCase folder.

Some code almost similar to the code in the extern program (I cant
change it):
up = some proxy method to connect to user
input up.getfile("file.txt")

How do i redirect the extern programs file request to another folder.
And i cant change the externprogram.

Is ther som way to do it, or must i give up and just keep all files
cluttered in the main prog directory?
--
Posted via http://www.yqcomputer.com/
 
 
 

External prog get file from main dir, want file in diff dir

Post by Jamis Buc » Sat, 27 Jun 2009 22:08:45

Dir.chdir() should do what you want, e.g.:

system("pwd")
Dir.chdir("CaseX") { system("pwd") }

Within the block, the working directory is the argument to Dir.chdir.
When the block finishes, the working directory is automatically reset
to what it was before.

- Jamis

 
 
 

External prog get file from main dir, want file in diff dir

Post by Kga Ag » Tue, 30 Jun 2009 23:09:04


A million thanks. It worked.
--
Posted via http://www.yqcomputer.com/