Need tutoring on using a path environment variable

D

dkmd_nielsen

I don't know what to do. I have an environment variable, PW_PATH,
that contains the folder names where applications can be executed
from. I want to start a particular application that is in one of
those folders. I currently use the following:

system("presort /a /nos /watch #{template[0]}") # submit the
presort to run

This works when the contents of PW_PATH are added to the PATH
variable. But I would like to avoid that if I can. I guess my
questions are: How do I first acquire the contents of PW_PATH? How
do employ the contents as a temporary addition to PATH so that system
can submit the application and it will be found and executed?

Suggestions? Comments? Observations? All are appreciated.

dvn
 
S

Siep Korteling

dkmd_nielsen said:
I don't know what to do. I have an environment variable, PW_PATH,
that contains the folder names where applications can be executed
from. I want to start a particular application that is in one of
those folders. I currently use the following:

system("presort /a /nos /watch #{template[0]}") # submit the
presort to run

This works when the contents of PW_PATH are added to the PATH
variable. But I would like to avoid that if I can. I guess my
questions are: How do I first acquire the contents of PW_PATH? How
do employ the contents as a temporary addition to PATH so that system
can submit the application and it will be found and executed?

Suggestions? Comments? Observations? All are appreciated.

dvn

ENV contains all environment variables; ENV['PW_PATH'] is the content of
PW_PATH. So this might be sufficient:

system("#{ENV['PW_PATH']/presort /a /nos /watch #{template[0]}")

hth,

Siep
 
D

dkmd_nielsen

I don't know what to do.  I have an environment variable, PW_PATH,
that contains the folder names where applications can be executed
from.  I want to start a particular application that is in one of
those folders.  I currently use the following:

      system("presort /a /nos /watch #{template[0]}") # submit the
presort to run

This works when the contents of PW_PATH are added to the PATH
variable.  But I would like to avoid that if I can.  I guess my
questions are:  How do I first acquire the contents of PW_PATH?  How
do employ the contents as a temporary addition to PATH so that system
can submit the application and it will be found and executed?

Suggestions?  Comments?  Observations?  All are appreciated.

dvn

First question answered: pw = ENV['pw_path'] I got that. But I
don't know how to employ the contents such that when the application
is submitted via system that the o/s actually knows where to go
looking.
 
D

dkmd_nielsen

dkmd_nielsen said:
I don't know what to do.  I have an environment variable, PW_PATH,
that contains the folder names where applications can be executed
from.  I want to start a particular application that is in one of
those folders.  I currently use the following:
      system("presort /a /nos /watch #{template[0]}")  # submitthe
presort to run
This works when the contents of PW_PATH are added to the PATH
variable.  But I would like to avoid that if I can.  I guess my
questions are:  How do I first acquire the contents of PW_PATH?  How
do employ the contents as a temporary addition to PATH so that system
can submit the application and it will be found and executed?
Suggestions?  Comments?  Observations?  All are appreciated.

ENV contains all environment variables; ENV['PW_PATH'] is the content of
PW_PATH. So this might be sufficient:

system("#{ENV['PW_PATH']/presort /a /nos /watch #{template[0]}")

hth,

Siep

Thanks, Siep. I will give this a shot. Not sure if linux and windows/
dos will treat it the same, but I guess that's my job to figure out.
 
D

dkmd_nielsen

Let's provide more information. The contents of pw_path include this:

C:\PW\firstprep;C:\PW\rapid\docs;C:\PW\la;C:\PW\rapid;c:\pw\pst;

And the application I want to execute is presort.exe, which is located
in c:\pw\pst;

I would like to be able to tell the O/S you have to look in the above
folders to find presort.exe, just as you would using PATH. In a
sense, I would like to temporarily merge the contents of pw_path into
the search path of PATH.

Is that better?
dvn
 
R

Rolando Abarca

Let's provide more information. The contents of pw_path include this:

C:\PW\firstprep;C:\PW\rapid\docs;C:\PW\la;C:\PW\rapid;c:\pw\pst;

And the application I want to execute is presort.exe, which is located
in c:\pw\pst;

I would like to be able to tell the O/S you have to look in the above
folders to find presort.exe, just as you would using PATH. In a
sense, I would like to temporarily merge the contents of pw_path into
the search path of PATH.

Is that better?

you can always store the path before and reset it after the system call:

old_path = ENV['path']
ENV['path'] << ENV['PW_PATH']
system(...)
ENV['path'] = old_path


regards,
 
R

Rob Biedenharn

Let's provide more information. The contents of pw_path include
this:

C:\PW\firstprep;C:\PW\rapid\docs;C:\PW\la;C:\PW\rapid;c:\pw\pst;

And the application I want to execute is presort.exe, which is
located
in c:\pw\pst;

I would like to be able to tell the O/S you have to look in the above
folders to find presort.exe, just as you would using PATH. In a
sense, I would like to temporarily merge the contents of pw_path into
the search path of PATH.

Is that better?

you can always store the path before and reset it after the system
call:

old_path = ENV['path']
ENV['path'] << ENV['PW_PATH']
system(...)
ENV['path'] = old_path

regards,


Of course, doing that kind of thing in Ruby should look like:

begin
old_path = ENV['path']
ENV['path'] << ENV['PW_PATH']
system(...)
ensure
ENV['path'] = old_path
end

-Rob

Rob Biedenharn http://agileconsultingllc.com
(e-mail address removed)
 
R

Rolando Abarca

Of course, doing that kind of thing in Ruby should look like:

begin
old_path = ENV['path']
ENV['path'] << ENV['PW_PATH']
system(...)
ensure
ENV['path'] = old_path
end

totally right... although, I don't think that system will raise an
exception. Maybe if PATH is blank (i.e. nil), concatenating the other
environmental variable will raise an exception.
-Rob

Rob Biedenharn http://agileconsultingllc.com
(e-mail address removed)


regards,
 
Y

Yossef Mendelssohn

you can always store the path before and reset it after the system call:

old_path =3D ENV['path']
ENV['path'] << ENV['PW_PATH']
system(...)
ENV['path'] =3D old_path
First,
str =3D 'blah' =3D> "blah"
old_str =3D str =3D> "blah"
str << 'test' =3D> "blahtest"
str =3D> "blahtest"
old_str
=3D> "blahtest"

Maybe you mean ENV['path'] +=3D ENV['PW_PATH'], or maybe you mean
old_path =3D ENV['path'].dup

Second, paths have separators, so simply sticking two different path
strings together is going to make something strange at the join.

Third, I think you mean ENV['PATH'], not ENV['path'].


HTH HAND
 
R

Rolando Abarca

Maybe you mean ENV['path'] += ENV['PW_PATH'], or maybe you mean
old_path = ENV['path'].dup

oops... you're right (I always forget about this! I even wrote a
question about this for the ruby-basic java black belt[1]
certification test :p)
Second, paths have separators, so simply sticking two different path
strings together is going to make something strange at the join.

yes sir, I skip those on purpose... :) (it was too late and it was
the last email I wrote before going to bed. I think that the OP should
know that PATH is a list of directories that are separated by
something, or at least he has the notion, so I only provided an idea
on how to solve his problem, not a complete solution, which, IMHO is
the best thing, because when you provide a complete solution, most
people stick to that and don't think too much around it).
Anyway, you should add the path like this:

ENV['PATH'] += ";#{ENV['PW_PATH']}" # just in case ENV['PW_PATH'] is nil

even if PATH has a ";" at the end, it does no harm to have another one.
Third, I think you mean ENV['PATH'], not ENV['path'].

That's also correct.


[1] http://www.javablackbelt.com/QuestionnaireDefDisplay.wwa?questPublicId=01548

regards,
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top