How to set env variable in shell

Hi,

The below “myusernam” has a password in PostgreSQL.
By using a shell object, I wanted to set PGPASSWORD env variable to avoid password authentication in Windows.

– Sync Shell
ShellCommand::::: set PGPASSWORD=mypassword & psql.exe -p 5433 -U myusername -s postgres

However, it seems that the above ‘set’ command doesn’t work.
I got “psql: FATAL: password authentication failed for user” error. It says that the env variable is not set correctly.

When I run the below command first in Windows prompt and then run “psql.exe” command, it works though.

set PGPASSWORD=mypassword

How can I set the PGPASSWORD env variable in this situation?

Thanks in advance.

Can you ‘pipe’ this like commandA | commandB?

set PGPASSWORD=mypassword | psql.exe -p 5433 -U myusername -s postgres

Sorry to say that: it is the same result.

http://forums.realsoftware.com/viewtopic.php?t=24409

this works:

  dim s as new Shell
  s.execute "export TEST=mytest;echo $TEST"

you will get “mytest” in the message box, meaning the “echo” command recognized it.

btw, pipe is meant to redirect A output to B input, while in this case are two different commands.

Great!!

I could manage to set env variable with following code.
System.EnvironmentVariable(“PGPASSWORD”) = “mypasswd”

Otherwise, you may want to use ‘pgpass.conf’ file to avoid password authentication but your password can be seen.

Thank you so much.

@ Massimo Valle
My environment is Windows. Thanks.

[quote=236401:@Wolfgang Meier]Can you ‘pipe’ this like commandA | commandB?

set PGPASSWORD=mypassword | psql.exe -p 5433 -U myusername -s postgres

On Windows, use an ampersand (&) and on Linux / OS X, use a semi-colon (:wink: between the two commands instead of the pipe (|).