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

K

Kga Agk

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?
 
J

Jamis Buck

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
 
K

Kga Agk

Jamis said:
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


A million thanks. It worked.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top