Reading environment variables

Hello!

I am trying to collect environment variables from within RPA.

  • Microsoft Windows 10
  • RPA Express 2.3.0

Recorder snippet:

Clipboard (clear)
Enter Keystrokes (Win+r)
Enter Keystrokes (typed text) | cmd.exe /c echo %ORACLE_HOME% | clip
Enter Keystrokes ({ENTER})
Clipboard (to 'env_oracle')

Environment variable [ORACLE_HOME]=[C:\Oracle1210_32\product\12.1.0\client_1]

Issuing [cmd.exe /c echo %ORACLE_HOME% | clip] at WIN+R directly from the Windows desktop works as expected: the value of ORACLE_HOME is copied to the clipboard.

However, after undertaking the same action in RPA, the env_oracle remains blank.

Questions:

  1. Why is this happening? Can I not rely on the clipboard to move data between RPA and the Windows command line?
  2. Is there a better way to capture values of Windows environment variables?

Hi @john_grant.

I think this is to be easier to use Custom Script in your case. Please see the sample below. Don’t forget to create Recorder variable var_value with String type.

@CustomScriptAction(
    output = 'var_value'
)
def GetSystemVariable() {
    def env = System.getenv()
    var_value = RString.of(env['OS'].toString())
}

More Custom Scripts samples can be found here - Custom Script samples.

1 Like

Thanks for that! It works, re: collecting environment variables.

I checked the Custom Script Samples page, and didn’t see anything, re: executing Windows shell commands and accessing the clipboard.

I am creating a series of checks for my RPAx bot that validate the server environment before launching the main process. I need to confirm that environment variables have been set, config files exist, software has been installed in the PATH, etc.

I can’t do most of that with the default RPAx controls. I can do that easily with Windows cmd.exe statements, and I can trap the information I need in the Windows clipboard. However: as with the original ORACLE_HOME clip above, RPAx doesn’t seem to connect to the “real” Windows clipboard during execution.

For example: If I run a program that writes to stdout:

"C:\Program Files\Oracle SQLcl\bin\sql.exe" -v
SQLcl: Release 19.2.1.0 Production

I can send that output to the Windows clipboard:

"C:\Program Files\Oracle SQLcl\bin\sql.exe" -v | clip

How do I recover that information from the Windows clipboard from within RPAx?