Skip to main content
Solved

How to use Environment Variables in User Parameters ?


Forum|alt.badge.img+1

Hello,

I'm working with FME Desktop 2015 with a WorkspaceRunner transformer calling several workspaces where i have to use an environment variable in the path of some private variables.

For example: %ENVIRONVAR%\\dat\\myfile.txt

The problem is that the called workspaces don't recognize the value of the environment variable defined by the Windows System. I have tried to assign the value to the environment variable inside the workspace but it is not a good solution in this case because every PC could have a different value.

Is there some example about to do solve this problem?

Many thanks in advance!

A.

Best answer by mark2atsafe

Use ${variablename} and that should work, for example: ${ENVIRONVAR}\\dat\\myfile.txt

View original
Did this help you find an answer to your question?

15 replies

takashi
Contributor
Forum|alt.badge.img+19
  • Contributor
  • March 15, 2016

Hi @ari, can the EnvironmentVariableFetcher transformer help you?


david_r
Evangelist
  • March 15, 2016

Hi

Are you using the EnvironmentVariableFetcher?

Be aware that environment variables defined while a program (e.g. FME) is running won't be available to that program until it restarts.

David


mark2atsafe
Safer
Forum|alt.badge.img+43
  • Safer
  • Best Answer
  • March 15, 2016

Use ${variablename} and that should work, for example: ${ENVIRONVAR}\\dat\\myfile.txt


Forum|alt.badge.img+1
  • Author
  • March 16, 2016

Thks Takashi, David & Mark for your anwers ! 

@Mark, I don't understand the reason but this solution doesn't work. I think it's the most logical way to do it and It was the first thing that i tried but I get this error message: 

Undefined macro `ENVIRONVAR' dereferenced in file `file.fmw'. Program Terminating

@Takashi, @David, I haven't used before the EnvironmentVariableFetcher transformer, I would take in consideraton for future ocassions. 

Finally, I solved the problem with a Private Scripted (Python) Parameter (myparam) that gets the value of the environment variable:

import os 
return os.environ['ENVIRONVAR']

and then using this parameter in that way ... $(myparam)/dat/file.dat

Clearly, this is a workaround to do the same that i think it would have to do the direct assign of the environment variable :(

Thanks,

A.


mark2atsafe
Safer
Forum|alt.badge.img+43
  • Safer
  • March 16, 2016
ari wrote:

Thks Takashi, David & Mark for your anwers ! 

@Mark, I don't understand the reason but this solution doesn't work. I think it's the most logical way to do it and It was the first thing that i tried but I get this error message: 

Undefined macro `ENVIRONVAR' dereferenced in file `file.fmw'. Program Terminating

@Takashi, @David, I haven't used before the EnvironmentVariableFetcher transformer, I would take in consideraton for future ocassions. 

Finally, I solved the problem with a Private Scripted (Python) Parameter (myparam) that gets the value of the environment variable:

import os 
return os.environ['ENVIRONVAR']

and then using this parameter in that way ... $(myparam)/dat/file.dat

Clearly, this is a workaround to do the same that i think it would have to do the direct assign of the environment variable :(

Thanks,

A.

That's odd @ari - are you sure you were using curly braces {} and not round ones ()


Forum|alt.badge.img+1
  • Author
  • March 17, 2016

Wow, It works ... :-D

Thanks a lot @Mark !

A.


Forum|alt.badge.img+1

The curly braces not working at 2017.0


Forum|alt.badge.img+1

So, I needed to restart services after creating environment variable. Sorry.


rwhittington
Contributor
Forum|alt.badge.img+1

Hi @mark2atsafe Thanks for this tip....this works well within the engine...but the environment variables in paths doesnt quite work within workbench for example when the FeatureReader wants to scan the dataset the environment variable in a path does not resolve.


mark2atsafe
Safer
Forum|alt.badge.img+43
rwhittington wrote:

Hi @mark2atsafe Thanks for this tip....this works well within the engine...but the environment variables in paths doesnt quite work within workbench for example when the FeatureReader wants to scan the dataset the environment variable in a path does not resolve.

fyi for everyone following this, I've filed the issue of environment variables in the FeatureReader (FMEENGINE-60160) and we'll wait and see what the developers can do for us.


ssharp
Participant
Forum|alt.badge.img
  • Participant
  • March 7, 2022
mark2atsafe wrote:

fyi for everyone following this, I've filed the issue of environment variables in the FeatureReader (FMEENGINE-60160) and we'll wait and see what the developers can do for us.

Has this "limitation" be address? Which approach is considered a FME developer "best practice", 1) EnvironmentVariableFetcher or 2) inline reference ${variablename}?


mark2atsafe
Safer
Forum|alt.badge.img+43
mark2atsafe wrote:

fyi for everyone following this, I've filed the issue of environment variables in the FeatureReader (FMEENGINE-60160) and we'll wait and see what the developers can do for us.

Unfortunately, no. The management team told me that this isn't meant to be supported, which is a shame. Given that, I think the EnvironmentVariableFetcher transformer is perhaps the best practice solution. It's an extra transformer to add, but it is the most guaranteed to work.


Forum|alt.badge.img
  • February 2, 2023
mark2atsafe wrote:

fyi for everyone following this, I've filed the issue of environment variables in the FeatureReader (FMEENGINE-60160) and we'll wait and see what the developers can do for us.

@mark2atsafe​ ; @david_r​ 

i have trouble using variable environmental in feature writer transformer:

in dataset i use : ${KMOCShape}\\Facilities. I doesn't work. please advise. thanks. - it actually creates a folder ${KMOCShape}\\Facilities at the same location of its workspace.


david_r
Evangelist
  • February 3, 2023
mark2atsafe wrote:

fyi for everyone following this, I've filed the issue of environment variables in the FeatureReader (FMEENGINE-60160) and we'll wait and see what the developers can do for us.

If you're referring to a published parameter, you have to use parenthesis, not brackets. For example:

$(KMOCShape)\Facilities

If you're indeed referring an OS environment variable, I'd try using an EnvironmentVariableFetcher before the writer and using its output attribute in the writer path.


Forum|alt.badge.img
  • February 3, 2023
mark2atsafe wrote:

fyi for everyone following this, I've filed the issue of environment variables in the FeatureReader (FMEENGINE-60160) and we'll wait and see what the developers can do for us.

Thanks @david_r​ !! using parenthesis, i has the same issue as using brackets. it works with EnvironmentVaribaleFetcher. Thanks again!


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings