Passing parameters to psql.exe - windows

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.

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

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.

Related

Proper syntax for psexec.exe hostname with filename to start

I'm trying to use psexec.exe to fire up Excel and then use Excel to open a specific .xlsx file.
I've just started learning psexec and I have written commands that work 'incrementally' in order to be sure my initial building blocks were correct along the way. Decided to actually start with NOTEPAD and a specific TEXT FILE to start:
(Please note, my goal is to execute this process on the local machine, not a remote machine, and for it to be Interactive, thus the -i switch)
This Works (just opens a blank Notepad window)
"C:\Users\Username\OneDrive - OrgName\Desktop\RunAs Test\psexec.exe" -i -u domain\username -p Password C:\Windows\system32\notepad.exe
This does not work - and I am positive the exe path and the file path are correct, I've tried them separately
"C:\Users\Username\OneDrive - OrgName\Desktop\RunAs Test\psexec.exe" -i -u domain\username -p Password C:\Windows\system32\notepad.exe \\server\data\mpsc-users\UserName\Test\sadf.txt
(It just returns the boilerplate 3 lines copyright, but with no mention of Error Code or results at all. Nothing else happens)
PsTools.chm is very clear on why it wont work
"Arguments to pass (note that file paths must be absolute paths on the
target system)"
"psexec.exe" -i \\somewhere.... C:\Windows\system32\notepad.exe c:\users\Isaac\desktop\hello.txt
should work (if the file exists on the remote system)

What is the difference between !call and call in windows batch

There are 2 files: file1.bat, file2.cmd
file1.bat invokes file2.cmd through command:
db2cmd -i -c -w db2 !call file2 parm1 parm2
This command opens a DB2 command window at the same window and invokes file2.cmd
However, what I can't understand is the function of '!' in front of 'call'.
file2.cmd has below features:
1. DB connection: db2 connect to dbname user username using psw
2. File open: for /F "delims=;" %%i in (input.txt) do (do something)
If passing the incorrect parameters,
---------With 'call' in the file1 command, error shows:
SQL1024N A database connection does not exist. SQLSTATE=08003
---------With '!call' in the file1 command, error shows:
SQL1001N "xxx" is not a valid database name. SQLSTATE=2E000
The system cannot find the file \input.txt.
DB20000I The TERMINATE command completed successfully
So, it looks like 'call' invokes another file and break with high level error message once one of the command fail;
While '!call' invokes another file and continue to run all the commands insides even though there are error, then displays all the error messages of all the failure.
Can someone advise the difference between 'call' and '!call'?
Ok, so simply put, there is no function !call in batch/cmdline. So db2cmd.exe being a commandline processor itself, requires you to use system commands with a preceding !
So though you have a batch file that runs the command with parameters, effectively this is what happens. You are starting db2cmd from this cmd, it then requires you to call another batchfile, but seeing as we are not within the shell of cmd anymore, but rather inside of db2cmd you're then required to tell db2cmd that it is a system command you're executing by doing !call
You can test it by doing on its own db2cmd where you will get to a db2=> prompt and then try and use call vs !call from there.
As for your error message:
SQL1001N "xxx" is not a valid database name. SQLSTATE=2E000
The system cannot find the file \input.txt.
DB20000I The TERMINATE command completed successfully
Try and add a path to the input.txt file
for /F "delims=;" %%i in (C:\somepath\input.txt) do (
something
)
or place input.txt in your working dir.
There is an easier way to handle running Db2 CLP commands inside a Windows batch file.
Db2 on Windows requires that Db2 CLP commands run inside a db2cmd.exe window.
(otherwise a db2 command in a normal cmd.exe window may fail with an error).
The db2cmd.exe is shipped with the Db2 Client for windows.
The solution is to arrange that the script auto-detects whether it is running
inside db2cmd.exe , and if not then run itself under db2cmd.
With this approach the calling script (if there is one)
can simply contain "call file2.bat par1 parm2" and can be executed by the normal CMD.EXE,
while the "file2.bat" can then contain:
#set db2cmd="C:\Program Files\IBM\SQLLIB\BIN\db2cmd.exe"
#if "%DB2CLP%"=="" %db2cmd% /w /c /i "%0" %* && #goto :EOF
#rem If db2cmd.exe is on the system PATH then you can omit the set db2cmd line.
db2 connect to dbname user username using psw
...rest of script...
...you can use db2 CLP commands directly
The first line sets a variable to contain the fully qualified pathname to the db2cmd.exe executable. This is the default path so you may need to change the pathname to match your environment, and you can omit this if you are certain that db2cmd.exe will always be on the system path.
The second line tests if the script is running under db2cmd.exe (in which case the DB2CLP environment
variable will be set). If the script is not running under db2cmd.exe then the script runs itself
under db2cmd.exe passing on the same command-line parameters. If the script is already running under db2cmd.exe then continue to the next line.

"ERROR: Invalid syntax. Default option is not allowed more than '2' time(s)." using SETX

I thought I had this working at one time but recently my command quit working. My research here and abroad is not turning up anything I have not attempted already. Perhaps there is some other variable I am missing that SETX is looking at?
My command:
setx /s servername PATH "%Path%";"c:\program files (x86)\java\jre7\bin";"c:\program files (x86)\java\jre7\bin\client" /m
I have tried the same command against a couple of Win2k8 servers to no avail. This has worked but is now producing the error above. I usually run this within a batch file against a list of several servers to push Java out. (Path to java is not being set unless we manually create the entries when remotely installed.)
The existing path on the server I am attempting to update is this:
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%systemroot%\System32\WindowsPowerShell\v1.0\;C:\BMC\Patrol3\bin;C:\BMC\common\globalc\bin\Windows-x86;C:\BMC\common\globalc\bin\Windows-x86-64;C:\BMC\Patrol3\BEST1\9.5.00\bgs\bin
I did clean up a couple duplicate path entries. Aside from that I did not find anything unusual to me.
Edit:
Tweaking the command to remove some of the quotation marks does allow it to run but with that, it imports the path of the local system replacing the remote systems path and appends the desired path entries.
The revised command:
setx /s servername PATH "%Path%;c:\program files (x86)\java\jre7\bin;c:\program files (x86)\java\jre7\bin\client" /m
In hopes of fixing this new problem, I am attempting to run the command with psexec. Doing so brings me back to my original problem, "Default option is not allowed more than '2' time(s)". Depending on how I modify the quotes when using psexec I can get "To many Arguments" or command succeeded, path truncated which ends up being the local path being applied on the remote server once again.
The most promising of my attempts:
psexec \\servername -u domain\user -p p#ssw0rd "c:\windows\system32\setx" "Path "%Path%;c:\program files (x86)\java\jre7\bin;c:\program files (x86)\java\jre7\bin\client" /M"
Using the "-s" option on psexec produces the same error, just less detail.
I was able to update the path value on remote systems by creating a batch file to be executed remotely.
Contents of "setJava7path.cmd"
setx Path "%Path%";"%ProgramFiles(x86)%\java\jre7\bin";"%ProgramFiles(x86)%\java\jre7\bin\client" /m
To execute I utilized psexec which copied the batch file to the remote system and executed the command.
psexec \\systemname -c setJava7path.cmd
It adds / changes a line to my overall deployment script but that is livable.

How to call an executable file directly in notepad++?

In windows,I use the Notepad++ to write tex file, in the "run..." dialog,I input that:
cmd /k D:\CTEX\MiKTeX\miktex\bin\xelatex $(FULL_CURRENT_PATH)
then run it,however the result shows that 'xdvipdfmx' is not an executable file. But I am sure that I have add its path to the system environment variable,and when I direct run it in the terminal, it's ok.
So,I want to know what I should do to run it in the notepad++ correctly.
Try these improvements:
enclose paths into quotes to avoid problems with spaces
add .exe to executable file name
test the full command in command prompt to see if it works (replace $(FULL_CURRENT_PATH)) with actual file name
please let me know the result
Your example after changes:
cmd /k "D:\CTEX\MiKTeX\miktex\bin\xelatex.exe" "$(FULL_CURRENT_PATH)"
Test it in command prompt like:
cmd /k "D:\CTEX\MiKTeX\miktex\bin\xelatex.exe" "D:\Data\MyDoc1.tex"

Batch file doesn't execute specified .exe on remote computer

I am trying to install a program on a remote computer using a command line argument and a batch script. For testing, I'm installing Notepad++ as the program.
Here is the command line I'm using to access the remote computer:
psexec \\comp-2 -h -u localAdmin -p password -c -f C:\install-npp.bat
This is the batch file code I've written:
#echo off
#echo Hello this creates a pointless temp file >C:\temp\EmptyFile.txt
xcopy \\FILESVR\Shared\npp.exe C:\temp\npp.exe
start C:\temp\npp.exe
pause
(Please note: the second line is only to make sure that the script is in fact doing something).
When I run the psexec command listed above from my first computer, the EmptyFile.txt is created, and npp.exe is copied over to the temp directory, but the executable is never run.
What am i doing wrong? the machines are in a windows workgroup.
Thanks in advance!
the start command is waiting a title as first argument so try start "" c:\temp\npp.exe.
BTW looking at http://coreworx.blogspot.fr/2010/07/unattended-installation-notepad.html I saw you will have to add /S to make a silent install of npp

Resources