Archive: ExecWait and Redirection (Again)


ExecWait and Redirection (Again)
Hello. I'm using NSIS 1.98. I'm unsuccessfully executing MySQL and redirecting a file of SQL commands to it with my installer. I see someone else had this problem, but the proposed solution is not working for me. It was discussed here:

http://forums.winamp.com/showthread....ighlight=mysql

I have exactly duplicated the proposed solution by DarkTrain but it doesn't work. My file of SQL commands works perfectly when redirected from the command line. When my installer runs, the command shell flashes by but the SQL commands have not been executed. The NSIS progress window shows the command I'm trying to run (partially, it runs past the dialog so I can't see the end).
I'm at a loss for how to debug this. Any ideas?


You can hold your mouse on a line in the log to see the whole line.


Holding the mouse over the line to see the entire line works only in NSIS 2.

garrel, can you please paste here the exact code you are using to execute the MySQL queries in the file?


Thanks for responding. Here's my code. In this case $INSTDIR is set to C:\mysql (MySQL home directory).

SetOutPath $INSTDIR\bin
ExpandEnvStrings $0 %COMSPEC%
Exec '"$0" /C "C:\mysql\bin\mysql" < "C:\mysql\bin\test.sql"'

When this runs, the DOS shell flashes by, but when I reload the MySQL tables and look at the data, the commands obviously didn't run. I have removed almost all of my other logic in the NSIS script and isolated the problem to these lines. I'm running the installer on Windows 2000 using NSIS version 1.98.

Any troubleshooting tips you can suggest are very appreciated!


Try:

ExpandEnvStrings $0 "%COMSPEC%"
DetailPrint $0
StrCpy $1 '"$0" /C "$INSTDIR\bin\mysql.exe" < "$INSTDIR\bin\test.sql"'
DetailPrint $1
IfFileExists "$INSTDIR\bin\test.sql" +2
DetailPrint "test.sql not found!"
IfFileExists "$INSTDIR\bin\mysql.exe" +2
DetailPrint "MySQL.exe not found!"
ExecWait $1


and tell me what is the output that this script generates.

I forgot to mention that I've also tried modifying the SQL commands to force MySQL to hang (i.e. not adding a semicolon after a command) so I could see the execution of the commands, but the shell window just flashes by. The result leads me to believe the query is never running.


I tried the code you gave me, and added just a little bit to the end to display any errors from the ExecWait. Here's the code I tried:


Function configure

; run the MySQL monitor and redirect SQL file for setting
; up permissions
SetOutPath $INSTDIR\bin
ExpandEnvStrings $0 "%COMSPEC%"
DetailPrint $0
StrCpy $1 '"$0" /C "$INSTDIR\bin\mysql.exe" < "$INSTDIR\bin\test.sql"'
DetailPrint $1
IfFileExists "$INSTDIR\bin\test.sql" +2
DetailPrint "test.sql not found!"
IfFileExists "$INSTDIR\bin\mysql.exe" +2
DetailPrint "MySQL.exe not found!"
ExecWait $1 $3

IfErrors 0 noErrorsSeen
MessageBox MB_OK "Error: $3"
noErrorsSeen:

FunctionEnd


When I run the script, the DetailPrint lines do not display, so the files are being found. In addition, the MessageBox does not display. I've also tried this with SQL statements that should hang the window (i.e. no semicolon at the end of a command), and the shell window never halts, it just appears and disappears. I've attached a jpg that shows the installer progress window.

Thanks again for helping debug this problem.

Try attaching again please.


Trying to attach .jpg again...


Try:
Exec '"$0" /C "C:\mysql\bin\mysql" < "C:\mysql\bin\test.sql" > "$DESKTOP\mysql.log"'
and attach mysql.log.


Good suggestion to redirect to a log, but unfortunately it didn't help. I run the installer and it behaves exactly as it did before (shell opens then closes without expected results in MySQL db). However, this is interesting because the mysql.log file is NOT created. I searched my entire system for it and it doesn't exist.
Here's the code as it exists now, and a snapshot of the progress window is attached.


Function configure


; run the MySQL monitor and redirect temporary SQL file for setting
; up permissions
SetOutPath $INSTDIR\bin
ExpandEnvStrings $0 "%COMSPEC%"
DetailPrint $0
Sleep 3000
Exec '"$0" /C "C:\mysql\bin\mysql" < "C:\mysql\bin\test.sql" > "$DESKTOP\mysql.log"'

FunctionEnd

Well, it's supposed to be on your desktop... Any chance you can attach the SQL file too?


Yes, it should be on the desktop, but it isn't. I've searched my entire hard drive for it, and it doesn't exist. This seems to be a clue to why this isn't working, but I'm at a loss.

I've attached a file sql commands. The other file will be in a follow-up message. I've tried both of them, and the behavior is the same. I've renamed these from .sql to .txt for attaching to this posting. test1.txt should hang MySQL since it doesn't have a semicolon at the end of the second SQL command. test2.txt is the actual file I need to be redirected to MySQL.


And the other file of SQL commands...


Try:
Exec '$0 /C C:\mysql\bin\mysql.exe < C:\mysql\bin\test.sql > "$DESKTOP\mysql.log"'


That command line did it!!!!!!!

The redirect and filename didn't need to be quoted. THANK YOU so much for helping me troubleshoot this problem in a prompt manner. Hopefully this will help others as well.

Regards,
Garrel Renick


We are not finished yet, but I think I finally have a good idea about the source of the problem :)

This code, if works, should be the safest solution:

SetOutPath $INSTDIR\bin
ExpandEnvStrings $0 %COMSPEC%
GetFullPathName /SHORT $1 $INSTDIR\bin\test.sql
Exec '"$0" /C "$INSTDIR\bin\mysql.exe" < $1'


If that doesn't work, try the same trick with $INSTDIR\bin\mysql.exe (GetFullPathName /SHORT and no quotes).

You need to get the short path name because the file name might contain spaces and then the command won't work.