8

I need to create a PostgreSQL tablespace with Inno Setup.

Running this on the command line works:

SET PGPASSWORD=P0stgres
"C:\Program Files\PostgreSQL\9.4\bin\psql.exe" -h localhost -p 5432 -U postgres -d postgres -c "CREATE TABLESPACE TABLETEST OWNER postgres LOCATION E'{app}\\PATHTEST\\Db'"

But trying this in Inno Setup does not work:

[Run]
Filename: {sys}\cmd.exe; Parameters: "SET PGPASSWORD=P0stgres"
Filename: {sys}\cmd.exe; Parameters: ""C:\Program Files\PostgreSQL\9.4\bin\psql.exe" -h localhost -p 5432 -U postgres -d postgres -c "CREATE TABLESPACE TABLETEST OWNER postgres LOCATION E'{app}\\PATHTEST\\Db'""

Regards

toraritte
  • 6,300
  • 3
  • 46
  • 67
Robertopcn
  • 447
  • 1
  • 5
  • 15

3 Answers3

4

I am able to do it. There should be no space between password and &. PGPASSWORD=password&

Filename: "cmd.exe"; Parameters: "/c set PGPASSWORD=my_db_user& ""psql"" -U my_db_user -d myappdb -a -q -f C:\my\Manager\SQL\Sequences.sql & pause"; Flags: runascurrentuser;
Max von Hippel
  • 2,856
  • 3
  • 29
  • 46
1

You have three problems:

  • The cmd.exe needs /C switch before the command.
  • The environment variable is not magically exported to the second cmd.exe instance that runs the psql.exe. You have to execute both commands within the same cmd.exe instance. One of the ways is using & "operator" (another way is using a wrapper batch file to execute both commands).
  • The double-quotes (particularly those around the C:\...\psql.exe and CREATE TABLESPACE ...) have to be doubled.
  • Not a problem per se, but you should better use {cmd} constant instead of {sys}\cmd.exe.
[Run]
Filename: "{cmd}"; Parameters: "/C SET PGPASSWORD=P0stgres& ""C:\Program Files\PostgreSQL\9.4\bin\psql.exe"" -h localhost -p 5432 -U postgres -d postgres -c ""CREATE TABLESPACE TABLETEST OWNER postgres LOCATION E'{app}\\PATHTEST\\Db'"""
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
0

I was able to do it work. Was a little mistake. The correct is:

[Run]
Filename: {cmd}; Parameters: "/K SET PGPASSWORD=P0stgres&""C:\Program Files\PostgreSQL\9.4\bin\psql.exe"" -h localhost -p 5432 -U postgres -d postgres -c ""CREATE TABLESPACE TABLETEST OWNER postgres LOCATION '{app}\PATHTEST\Db'""
Luc M
  • 16,630
  • 26
  • 74
  • 89
Robertopcn
  • 447
  • 1
  • 5
  • 15