0

I cannot find any answer to run a Linux command with header environment variable in JAVA.

The example command like this.

PGPASSWORD="mypassword" psql -h '12.34.56.78' -p '12345' -d 'testdb' -U 'testuser' -c "vacuum analyze dw.test"

I am not successful with Runtime.exec, because it recognizes the first one as a command, but psql is the real command.

How can I run this command in JAVA, like shown below?

system("PGPASSWORD="mypassword" psql -h '12.34.56.78' -p '12345' -d 'testdb' -U 'testuser' -c "vacuum analyze dw.test"")
jww
  • 97,681
  • 90
  • 411
  • 885
minsu
  • 31
  • 1
  • 1
    I think your "header" there is actually called an environment variable. Could you double check that's indeed what you're doing here? – markspace Mar 24 '18 at 02:21
  • [How do I set environment variables from Java?](https://stackoverflow.com/q/318239/608639), [How to set an environment variable in Java using exec?](https://stackoverflow.com/q/8607249/608639), [Executing an external program with path variable set in Java?](https://stackoverflow.com/q/11885326/608639), [Execute external program in java](https://stackoverflow.com/q/13991007/608639), [Executing external program in java and passing commands](https://stackoverflow.com/q/9958629/608639), [Execute external program from Java](https://stackoverflow.com/q/2874591/608639), etc. – jww Mar 24 '18 at 07:16

0 Answers0