# Need to carry over application variable into RUBY script

**URL:** <https://www.ruby-forum.com/t/need-to-carry-over-application-variable-into-ruby-script/58003>\
**Category:** Ruby\
**Created:** [April 17, 2006, 6:13pm UTC](https://www.ruby-forum.com/t/need-to-carry-over-application-variable-into-ruby-script/58003 "2006-04-17T18:13:14Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![bodikp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@bodikp](https://www.ruby-forum.com/u/bodikp)\
**Post date:** [April 17, 2006, 6:13pm UTC](https://www.ruby-forum.com/t/need-to-carry-over-application-variable-into-ruby-script/58003/1 "2006-04-17T18:13:14Z")

</div>

I have an application that converts PDFs to individual EPS files. When  
it does so, it creates a subdirectory with the same name as the original  
filename and puts all of the resulting EPS files it creates into that  
directory. Well, I have to do a lot of scripting and stuff on those EPS  
files. To automate this, I need to know what the directory name is that  
it put the files. The application provides a variable, “%2,” just for  
this purpose. I’ve gotten this %2 variable to work for me in cmd.exe.  
But, I’d like it to work in RUBY. I’m sure it can be done. But, came  
someone tell me how I can transfer this %2 variable from my application  
to a Dir.chdir target?

Example:  
A 100 page PDF comes in named IRSp590. The application creates a  
subdirectory named “IRSp590.” All of the files the application creates  
are put into this directory. I just need to get into that directory,  
wherever it is, and do stuff to the files.

Thanks.

---

<div class="post-metadata">

**Author:** ![bodikp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@bodikp](https://www.ruby-forum.com/u/bodikp)\
**Post date:** [April 17, 2006, 6:19pm UTC](https://www.ruby-forum.com/t/need-to-carry-over-application-variable-into-ruby-script/58003/2 "2006-04-17T18:19:21Z")

</div>

On 4/17/06, Peter B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have an application that converts PDFs to individual EPS files. When  
> it does so, it creates a subdirectory with the same name as the original  
> filename and puts all of the resulting EPS files it creates into that  
> directory. Well, I have to do a lot of scripting and stuff on those EPS  
> files. To automate this, I need to know what the directory name is that  
> it put the files. The application provides a variable, “%2,” just for  
> this purpose. I’ve gotten this %2 variable to work for me in cmd.exe.  
> But, I’d like it to work in RUBY. I’m sure it can be done. But, came  
> someone tell me how I can transfer this %2 variable from my application  
> to a Dir.chdir target?

%2 is the 2nd argument on the command-line, so you just have to look  
for ARGV[2].

It’d be interesting to find out what %1 is 😉

-austin

---

<div class="post-metadata">

**Author:** ![bodikp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@bodikp](https://www.ruby-forum.com/u/bodikp)\
**Post date:** [April 17, 2006, 7:13pm UTC](https://www.ruby-forum.com/t/need-to-carry-over-application-variable-into-ruby-script/58003/3 "2006-04-17T19:13:30Z")

</div>

Austin Z. wrote:

> On 4/17/06, Peter B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > I have an application that converts PDFs to individual EPS files. When  
> > it does so, it creates a subdirectory with the same name as the original  
> > filename and puts all of the resulting EPS files it creates into that  
> > directory. Well, I have to do a lot of scripting and stuff on those EPS  
> > files. To automate this, I need to know what the directory name is that  
> > it put the files. The application provides a variable, “%2,” just for  
> > this purpose. I’ve gotten this %2 variable to work for me in cmd.exe.  
> > But, I’d like it to work in RUBY. I’m sure it can be done. But, came  
> > someone tell me how I can transfer this %2 variable from my application  
> > to a Dir.chdir target?
> 
> %2 is the 2nd argument on the command-line, so you just have to look  
> for ARGV[2].
> 
> It’d be interesting to find out what %1 is 😉
> 
> -austin

Thanks, Austin. So, do I do this?

Dir.chdir(ARGV[2])  
or this  
Dir.chdir(“ARGV[2]”)?

---

<div class="post-metadata">

**Author:** ![bodikp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@bodikp](https://www.ruby-forum.com/u/bodikp)\
**Post date:** [April 17, 2006, 8:24pm UTC](https://www.ruby-forum.com/t/need-to-carry-over-application-variable-into-ruby-script/58003/4 "2006-04-17T20:24:43Z")

</div>

Austin Z. wrote:

> On 4/17/06, Peter B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > > > someone tell me how I can transfer this %2 variable from my application  
> > > > Dir.chdir(“ARGV[2]”)?  
> > > > Never the latter.
> 
> I’m presuming that what you actually have is a command-line entry box  
> in your Windows program:
> 
> [post\_process\_script %2]
> 
> If that’s how you’re configuring it, then your Ruby code must be  
> looking for ARGV[1], not ARGV[2].
> 
> -austin

No, there’s no command line entry box. It’s just an understood variable  
that the application can use in a post-processing script, which, usually  
is, of course, a .cmd script. In a simple Windows script, for example,  
you could do this:  
cd %2  
and you would go to the directory path of the file that the application  
produced.

---

<div class="post-metadata">

**Author:** ![bodikp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@bodikp](https://www.ruby-forum.com/u/bodikp)\
**Post date:** [April 17, 2006, 7:43pm UTC](https://www.ruby-forum.com/t/need-to-carry-over-application-variable-into-ruby-script/58003/5 "2006-04-17T19:43:34Z")

</div>

On 4/17/06, Peter B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > someone tell me how I can transfer this %2 variable from my application  
> > > Dir.chdir(“ARGV[2]”)?  
> > > Never the latter.

I’m presuming that what you actually have is a command-line entry box  
in your Windows program:

[post\_process\_script %2]

If that’s how you’re configuring it, then your Ruby code must be  
looking for ARGV[1], not ARGV[2].

-austin

---

<div class="post-metadata">

**Author:** ![bodikp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@bodikp](https://www.ruby-forum.com/u/bodikp)\
**Post date:** [April 17, 2006, 8:32pm UTC](https://www.ruby-forum.com/t/need-to-carry-over-application-variable-into-ruby-script/58003/6 "2006-04-17T20:32:53Z")

</div>

On 4/17/06, Peter B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> No, there’s no command line entry box. It’s just an understood variable  
> that the application can use in a post-processing script, which, usually  
> is, of course, a .cmd script. In a simple Windows script, for example,  
> you could do this:  
> cd %2  
> and you would go to the directory path of the file that the application  
> produced.

OK. Then you need ARGV[2].

-austin

---

<div class="post-metadata">

**Author:** ![bodikp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@bodikp](https://www.ruby-forum.com/u/bodikp)\
**Post date:** [April 17, 2006, 8:47pm UTC](https://www.ruby-forum.com/t/need-to-carry-over-application-variable-into-ruby-script/58003/7 "2006-04-17T20:47:48Z")

</div>

Austin Z. wrote:

> On 4/17/06, Peter B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > No, there’s no command line entry box. It’s just an understood variable  
> > that the application can use in a post-processing script, which, usually  
> > is, of course, a .cmd script. In a simple Windows script, for example,  
> > you could do this:  
> > cd %2  
> > and you would go to the directory path of the file that the application  
> > produced.
> 
> OK. Then you need ARGV[2].
> 
> -austin

Thank you!
