JnF
JnF

Reputation: 21

How to write a .bat file in nsis script

$INSTDIR\DOWNPRINT\runRestart.bat" "TEXT" "@ECHO OFFdel $INSTDIR\DOWNPRINT\process.txtwmic process  get processid,name,commandline /format:csv | findstr "runPosiboltprint.bat" | findstr /V "findstr"  > $INSTDIR\DOWNPRINT\process.txt(for /f "tokens=3,* delims=," %%a in($INSTDIR\DOWNPRINT\process.txt) do @echo %%b) >$INSTDIR\DOWNPRINT\pid.txtcd $INSTDIR\DOWNPRINT\SET /P A= < $INSTDIR\DOWNPRINT\pid.txttaskkill.exe /F  /PID  %A%$INSTDIR\Java\bin\java.exe -jar $INSTDIR\DOWNPRINT\printer.jar

this is my batch script

i already tried FileWrite and WriteIniStr. But both are throwing an error like WriteIniStr expects 4 parameters, got 28. and FileWrite expects 4 parameters, got 28.

ANYBODY PLEASE HELP ME!

Upvotes: 2

Views: 915

Answers (1)

Anders
Anders

Reputation: 101569

You need to quote the string when using FileWrite:

Section
InitPluginsDir
FileOpen $0 "$pluginsdir\myscript.bat" w
FileWrite $0 '@echo off$\r$\n'
FileWrite $0 'echo Hello world$\r$\n'
FileWrite $0 'echo foo "bar" | find /I "FOO" > $pluginsdir\temp.txt $\r$\n'
FileClose $0

ReadEnvStr $0 COMSPEC
nsExec::Exec  '"$0" /c "$pluginsdir\myscript.bat"' ; Run the batch with a hidden window. Use ExecWait if you want a visible window
Pop $0
DetailPrint "Returned $0"
SectionEnd

Upvotes: 2

Related Questions