- NSIS Discussion
- Execute command line tool
Archive: Execute command line tool
Swapan Das
20th December 2007 08:31 UTC
Execute command line tool
Dear All,
I want to execute certain sql query using sqlcmd command line tool. Please let me know how to execute the following command directly from nsis, without calling from a batch file and using nsExec::Exec
SQLCMD -S . -E -o Output1.Txt -Q "ALTER LOGIN sa WITH PASSWORD= '', CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF"
Regards,
Swapan
Swapan Das
20th December 2007 09:16 UTC
Plz. note that the total command of SQLCMD is in a single line.
wongbego
20th December 2007 11:59 UTC
Hi,
this is what I use to start Oracle SQLPlus with SQL commands in a SQL file and put all out put in the details.
Perhaps it can help you.
SetOutPath "$TEMP"
File "drop_schema_for_restore.sql"
#Exec the SQLPLUS command. Use drop database schema.
#$oracleSqlplus contains absolute path of the sqlplus.exe
nsExec::ExecToLog /OEM '"$oracleSqlplus" -L $oracleUserPassword "@$TEMP\drop_schema_for_restore.sql"'
Swapan Das
20th December 2007 14:32 UTC
wongbego Thanks for the reply.
But I don't want to use any external file (batch or sql query file) for this, any way out?
Regards,
Swapan Das
21st December 2007 09:02 UTC
Why the following is not working from command prompt (cmd.exe). The file does exists in the supplied path and the path is correct also.
C:\Program Files\Microsoft SQL Server\90\Tools\Binn\SQLCMD.EXE
It gives error:
'C:\Program' is not recognized as an internal or external command, operable program or batch file.
And in NSIS Script I've done this:
ReadRegStr $R1 HKLM "SOFTWARE\Microsoft\Microsoft SQL Server\90\Tools\ClientSetup" "SQLPath"
ReadRegStr $R2 HKLM "SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName" "ComputerName"
FileOpen "$R0" "Login.txt" "w"
FileWrite "$R0" "ALTER LOGIN sa WITH PASSWORD= '',CHECK_EXPIRATION=OFF,CHECK_POLICY=OFF$\r$\n"
FileClose "$R0"
nsExec::Exec "cmd /C $R1\Binn\SQLCMD -S $R2\MYSSE -E -o LoginError.Log -i Login.txt"
(MYSSE is my sql express instance name which already exists)
meaningoflights
14th January 2008 19:06 UTC
I woke up this morning at 3:30am, couldn't sleep! My setup fails to execute the cmd file, just like yours!!!
http://forums.winamp.com/showthread.php?s=&threadid=182096&highlight=nsExecExecToLog
http://forums.winamp.com/showthread.php?s=&threadid=276438&highlight=nsExecExecToLog
I just tried this and it didn't work 1st go.
System::Call 'kernel32.dll::WinExec(t "mysql.bat", i 0) i.r0'
Let me know your results too mate? Thanks
Anders
14th January 2008 19:18 UTC
Swapan Das:
'C:\Program' is not recognized << space in filename, use doublequotes (") nsExec::Exec 'cmd.exe /c "c:\foo space.exe" /param'
meaningoflights:
AFAIK, WinExec just calls CreateProcess, so you might aswell use the Exec nsis command
meaningoflights
14th January 2008 19:30 UTC
I'm trying to suss it. Getting a little bit further.
From my findings it appears cmd.exe doesn't like the path specified with the cmd file or enclosing the cmd file with quotes. See the 3 tests here:
http://jeremythompson.net/Rocks/pers...pleasehelp.jpg
How come Swapan & I cant get the cmd file to execute, but everyone else can using a path to their cmd file with quotes (eg "$TEMP\a.cmd" or "$INSTALLDIR\a.cmd") ???
nsExec::ExecToLog 'cmd.exe /C "$INSTDIR\CreateDatabase.cmd" "PCName\InstanceName" "DbName" "$INSTDIR\BackUpFile"'
Thanks in advance
Anders
14th January 2008 20:59 UTC
try
cmd /C if 1==1 "c:\somepath\foo.cmd" "bar" "baz"
or
cmd /C ""c:\somepath\foo.cmd" "bar" "baz""
Swapan Das
15th January 2008 05:48 UTC
Right now I'm not stucked with this issue. But after remaining clueless I had to take support of an external sql file which I didn't wished to do so. What I did and worked for me is given below:
ReadRegStr $R1 HKLM "SOFTWARE\Microsoft\Microsoft SQL Server\90\Tools\ClientSetup" "SQLPath"
FileOpen "$R0" "AlterLoginPswd.sql" "w"
FileWrite "$R0" "ALTER LOGIN sa WITH PASSWORD= '',CHECK_EXPIRATION=OFF,CHECK_POLICY=OFF$\r$\n"
FileClose "$R0"
${If} ${FileExists} $R1\Binn\SQLCMD.EXE
Sleep 3000
nsExec::Exec '"$PROGRAMFILES\Microsoft SQL Server\90\Tools\Binn\SQLCMD.EXE" -S $DataBaseServerName -E -o AlterLogin.Log -i "AlterLoginPswd.sql"'
Sleep 3000
${ELSE}
MessageBox MB_ICONEXCLAMATION|MB_OK "SQLCMD.EXE not found at pre-defined path, trying to run from current path.."
Sleep 3000
nsExec::Exec '"SQLCMD.EXE" -S $DatabaseServerName -E -o AlterLogin.Log -i "AlterLoginPswd.sql"'
Sleep 3000
${Endif}
Perhaps the "Sleep" is not required here. Let me know if it could've been done in more better and accurate way.
Regards,
meaningoflights
15th January 2008 07:33 UTC
Anders, I cant thank you enough.
I discovered the root cause, the cmd file did this:
BAD:
sqlcmd -S "%Instance%" -b -v Database="%Database%" SQLPath="" BackUpPath="%BackUpPath%" -i CreateDataBase.sql
GOOD:
sqlcmd -S "%Instance%" -b -v Database="%Database%" SQLPath="" BackUpPath="%BackUpPath%" -i "%SQLFilePath%"
Thanks again Anders.
Swapan Das if your not right as rain, shout out.
It was a pleasure to work with you guys on this issue.
Swapan Das
24th January 2008 06:54 UTC
Then what exactly would be the one line command to execute :
ALTER LOGIN sa WITH PASSWORD= '',CHECK_EXPIRATION=OFF,CHECK_POLICY=OFF
with the help of SQLCMD and nsExec::Exec ?
meaningoflights will be kind enough to pass the exact command so that I can straight way check it otherwise I'll stick to my method, which I've mentioned in my previous post.
Regards,