- NSIS Discussion
- Problem with macro parameters (bug?)
Archive: Problem with macro parameters (bug?)
pospec
14th September 2007 13:58 UTC
Problem with macro parameters (bug?)
Hello!
I've found one thing. If we have macro, that accepts some parameter and then try to call it:
!insertmacro foo 'bar' ; blah
then compiler exits with error. Isn't it bug in expanding macro? I think that it is, because comments should be removed from the line before expansion. I am using 2.28.
Afrow UK
14th September 2007 17:40 UTC
What is the exact error?
Comments works fine on my machine with makensis 2.29.
Stu
pospec
14th September 2007 17:53 UTC
Sorry guys, I must have made a make mistake elsewhere. When I was in an office, the compilator produced this error. I thought about it on the train on my way home and I simply couldn't believe that such a great installer could contain such a stupid bug. I came home and tried to write that macro and produce the error again. And nothing happened (either in 2.28 nor 2.30)! My aim was a macro, that executes command and checks for errors, something like this:
!macro MyExec command
ClearErrors
ExecWait command
${If} ${Errors}
MessageBox MB_OK|MB_ICONSTOP "Error! (${command})"
${EndIf}
!macroend
And then I replaced all occurencies of "ExecWait" to "!insertmacro MyExec", that should be OK.
So I am very sorry for starting this thread, delete it if you want. Have a nice weekend guys!
pospec
14th September 2007 17:58 UTC
Stu, the compilator said that I had 3 arguments to macro instead of 1 or 2. So I thought that it was a parser problem.
pospec
14th September 2007 18:44 UTC
I know where was problem - the ';' character was placed immediately after last character of macro. No whitespaces.
gustavo-serra
1st November 2007 13:40 UTC
I am having this problem, I have searched the forum for 'ExecWait macro' and found this thread. The compiler says that I am passing 8 arguments to ExecWait. This is my macro:
!macro MyExecWait comando
ExecWait ${comando}
IfErrors +1 +3
${MSG_ERROR} 'Não foi possÃ_vel executar comando. Instalação será abortada'
Abort
!macroend
!define MyExecWait '!insertmacro MyExecWait'
And I call it this way:
${MyExecWait} 'mysqldump -uroot -p123456 -a -c -r $INSTDIR\backup\controle.sql controle'
pospec I noticed that your ExecWait call does not use ${} around the command. I have tryed this, but then the ExecWait will execute 'command', literally.
Any help, please?
DrDan
1st November 2007 13:56 UTC
gustavo-serra, you need to do something like this to solve the problem:
!macro MyExecWait comando
ExecWait "${comando}"
IfErrors +1 +3
${MSG_ERROR} 'Não foi poss�_vel executar comando. Instalação será abortada'
.
.
.
Note the additional two " on the ExecWait line.
gustavo-serra
1st November 2007 14:42 UTC
I have just done this. However, I had to change my old commands, for example:
ExecWait 'mysql -e"commands to mysql"'
to
${MyExecWait} 'mysql -e$\"commands to mysql$\"'
Is this the normal behavior? If so, then everything is solved.
Thanks for the help!
Afrow UK
1st November 2007 15:30 UTC
If you think about it, if you pass 'my name is "stu"' into your macro as argument which in turn places it in Command "${argument}", then Command "${argument}" will become Command "my name is "stu"" which is of course an invalid string. Best thing to do is to use ``: Command `${argument}`.
Stu
gustavo-serra
1st November 2007 16:47 UTC
Oh! Thanks! I didn't know that I could use ` to group arguments. :-)