将 Inno Setup exec 函数中的命令传递到 pgsql 数据库中
Passing commands in Inno Setup exec function into pgsql database
我正在 运行宁以下代码试图从我的 Inno Setup 脚本读取的文件在我的 PostgreSQL 数据库中创建用户。不幸的是,唯一执行的命令是将我连接到数据库的 SET PGPPASSWORD
和 -U postgres elt
命令。我需要在数据库中 运行 的其他命令被忽略,我似乎无法找到将它们输入数据库的方法。我可以使用字符将命令输入到 PostgreSQL 数据库中吗?
ExecAsOriginalUser('cmd.exe', '/k ' +'"SET PGPASSWORD=postgres&"' +
InstallPath+ '\psql -U postgres elt -c '+ 'CREATE USER '
+ Users[UserCount - 1] + ' WITH PASSWORD ' + ''''
+ Password + '''' + '& ' + '\g', '', SW_SHOW, ewWaitUntilIdle, ResultCode);
命令行输出:
psql: warning: extra command-line argument "-c" ignored
"": extra command-line argument "CREATE" ignored
"": warning: extra command-line argument "USER" ignored
"": extra command-line argument "postgres" ignored
"": extra command-line argument "WITH" ignored
"": extra command-line argument "PASSWORD" ignored
"": extra command-line argument "'postgres'\g" ignorepsql
(9.5.3) WARNING: Console code page (437) differs from
Windows code page
(1252) 8-bit characters might not work correctly. See psql reference page
"Notes for Windows users" for details.
Type "help" for help.
db=#
您可能只需要将 SQL 括在双引号中:
ExecAsOriginalUser('cmd.exe',
'/c SET PGPASSWORD=postgres& '
+ InstallPath + '\psql -U postgres elt -c "CREATE USER '
+ Users[UserCount - 1] + ' WITH PASSWORD ''' + Password + '''"',
'', SW_SHOW, ewWaitUntilIdle, ResultCode);
首先在命令行中通过运行验证:
cmd.exe /c SET PGPASSWORD=postgres& C:\eltfiles\pgsql\bin\psql -U postgres elt -c "CREATE USER postgres WITH PASSWORD 'postgres'"
我正在 运行宁以下代码试图从我的 Inno Setup 脚本读取的文件在我的 PostgreSQL 数据库中创建用户。不幸的是,唯一执行的命令是将我连接到数据库的 SET PGPPASSWORD
和 -U postgres elt
命令。我需要在数据库中 运行 的其他命令被忽略,我似乎无法找到将它们输入数据库的方法。我可以使用字符将命令输入到 PostgreSQL 数据库中吗?
ExecAsOriginalUser('cmd.exe', '/k ' +'"SET PGPASSWORD=postgres&"' +
InstallPath+ '\psql -U postgres elt -c '+ 'CREATE USER '
+ Users[UserCount - 1] + ' WITH PASSWORD ' + ''''
+ Password + '''' + '& ' + '\g', '', SW_SHOW, ewWaitUntilIdle, ResultCode);
命令行输出:
psql: warning: extra command-line argument "-c" ignored
"": extra command-line argument "CREATE" ignored
"": warning: extra command-line argument "USER" ignored
"": extra command-line argument "postgres" ignored
"": extra command-line argument "WITH" ignored
"": extra command-line argument "PASSWORD" ignored
"": extra command-line argument "'postgres'\g" ignorepsql
(9.5.3) WARNING: Console code page (437) differs from
Windows code page
(1252) 8-bit characters might not work correctly. See psql reference page
"Notes for Windows users" for details.
Type "help" for help.
db=#
您可能只需要将 SQL 括在双引号中:
ExecAsOriginalUser('cmd.exe',
'/c SET PGPASSWORD=postgres& '
+ InstallPath + '\psql -U postgres elt -c "CREATE USER '
+ Users[UserCount - 1] + ' WITH PASSWORD ''' + Password + '''"',
'', SW_SHOW, ewWaitUntilIdle, ResultCode);
首先在命令行中通过运行验证:
cmd.exe /c SET PGPASSWORD=postgres& C:\eltfiles\pgsql\bin\psql -U postgres elt -c "CREATE USER postgres WITH PASSWORD 'postgres'"