9

I want to launch psql.exe from an application. The user locates the script, so it could be anywhere on his disk, and the application just feeds that script to psql. That's about it.

What's the correct command line for that ?

I tried this with no success

"C:\Program Files\PostgreSQL\9.1\bin\psql.exe" TEST SYSADM -f "C:\Documents and Settings\Administrateur\Mes documents\TD6.0\FETCHING\install.sql"

I tried with quotes, without the quotes, none worked, it's just ignoring the arguments (tried this on cmd.exe)

C:\Documents and Settings\Administrateur>"C:\Program Files\PostgreSQL\9.1\bin\psql.exe" TEST SYSADM -f "C:\Documents and Settings\Administrateur\Mes documents\TD6.0\FETCHING\install.
sql"
psql: warning: extra command-line argument "-f" ignored
psql: warning: extra command-line argument "C:\Documents and Settings\Administrateur\Mes documents\TD6.0\FETCHING\install.sql" ignored
Password for user SYSADM:

Yes, if the script is in the same directory as psql.exe, and if I CD first to where psql.exe is installed, that means no quotes, no absolute paths and it works fine. However, in my case, I want the application to work on any windows installation, that means psql.exe could be anywhere and the sql script also could be anywhere. I still want the script to be fed to psql.exe.

Quassnoi
  • 413,100
  • 91
  • 616
  • 614
ychaouche
  • 4,922
  • 2
  • 44
  • 52
  • 5
    If you look closely at the output of `psql --help` you'll notice that all "switch" parameters need to come *before* the database and user name –  May 22 '12 at 22:23

2 Answers2

7

Try this:

"C:\Program Files\PostgreSQL\9.1\bin\psql.exe" -f "C:\Documents and Settings\Administrateur\Mes documents\TD6.0\FETCHING\install.sql" TEST SYSADM 
Quassnoi
  • 413,100
  • 91
  • 616
  • 614
0

Save the commands below as a BATch file (install.bat, etc).

Note the 'defaultValueHere'. You can set the default value in case your user skips the entry.

SET installScript=defaultValueHere
SET /P server="Enter the install script location [%installScript%]: "
ECHO you typed %installScript%
PAUSE 
"C:\Program Files\PostgreSQL\9.1\bin\psql.exe" TEST SYSADM -f %installScript%

Instruct the user to launch the installation from the install.bat file. Also see my answer on passing parameters to the SQL script.

Community
  • 1
  • 1
MAbraham1
  • 1,717
  • 4
  • 28
  • 45