Skip to content
⌘ NSIS Forum Archive

NsExec: ExecToLog Run cscript.exe with unicode

6 posts

Pawel#edited

NsExec: ExecToLog Run cscript.exe with unicode

Hey,
I have a problem with some VBS script that displays Unicode characters.
I want to run the script via nsExec::ExecToLog to capture its output.
To force unicode output from cscript I use /U command. It should show output text
in Nsis installer log... it does not, why?

Here is a simple, example code:

Test_Unicode.nsi file:
  Unicode True
  !include "MUI2.nsh"
  !include "nsdialogs.nsh" 
  !include "WordFunc.nsh"
  !include "FileFunc.nsh"
  !include "WinVer.nsh"
  !include "LogicLib.nsh"  
  !include "x64.nsh"   
;--------------------------------
  Name "Test_Unicode"
  OutFile "Test_Unicode.exe"
    RequestExecutionLevel "admin"
    XPStyle on
    SetDatablockOptimize on
    SetCompressor /FINAL /SOLID LZMA
    ShowInstDetails show  
  !insertmacro MUI_PAGE_INSTFILES
 ;--------------------------------
    !define MUI_LANGDLL_ALLLANGUAGES
    !insertmacro MUI_RESERVEFILE_LANGDLL
; Polish
    !insertmacro MUI_LANGUAGE "Polish"
; English
    !insertmacro MUI_LANGUAGE "English"
    
;--------------------------------
;Installer Sections
ShowInstDetails Show
Function .oninit
    
    InitPluginsDir
    File "/oname=$PLUGINSDIR\VBS_Unicode.vbs" "VBS_Unicode.vbs"
    !insertmacro MUI_LANGDLL_DISPLAY        
    
FunctionEnd
Section "Run_VBS_Test_File" SecDummy2
    ${If} $Language = "1045" ;Polish 
        ${If} ${AtLeastWin7}
            DetailPrint ""
            ; Unicode
            nsExec::ExecToLog '"$SYSDIR\cscript.exe" /nologo /T:120 /U "$PLUGINSDIR\VBS_Unicode.vbs"'
            Pop $0
            DetailPrint "Return value: $0"
        ${EndIf}
    ${Else}
        MessageBox MB_OK "Please, run in Polish language, to see Unicode characters"
        
    ${EndIf}
        
SectionEnd
Section -Post
    SetAutoClose false
    
SectionEnd 

Example VBS file, VBS_Unicode.vbs:
WScript.Echo "Przykładowy tekst. ŚĆĘĄÓŁŃ"
WScript.Echo "Above means: Example text: Unicode letters" 
If I remove /U command, NSIS installer displays output text (however, incorrectly). When I use /U it doesn't show anything (I thought it should display correct unicode text).

This is just simple example, as my vbs script is complicated and adopted by me (my VB skills are very poor, so forgive me if I am totally wrong...)
Maybe you have some idea how to capture unicode text from cscript?
-Pawel
Anders#
Is this on a Win8 machine?

On a Win8 machine, running
cscript //NOLOGO //U C:\Users\Anders\AppData\Local\Temp\VBS_Unicode.vbs|find /V ""
in the console just gives me:

C:\Users\Anders\AppData\Local\Temp\VBS_Unicode.vbs(1, 1) (null): Incorrect function.
See also: http://stackoverflow.com/questions/1...m-in-windows-8
JasonFriday13#
I noticed that there's an error in your nsi script (there should be a \ between $PLUGINSDIR and the filename) which should be: 'File /oname=$PLUGINSDIR\VBS_Unicode.vbs "VBS_Unicode.vbs" '

I'm not using Windows atm so I can't test this.
Pawel#
@JasonFriday13
You are right, it wasn't displayed correctly here... In script it is OK.

@Anders
Yes, I have tested it on Win8.
You say then that on Win8 it is broken and it will not work?

PS: I have just tested it on Windows 7 and it works... so it must be some issue on Win8... I hope there is some solution.
Anders#
Report the issue to MS connect unless they already fixed it in 8.1.

The only workaround for Win8 is to use redirection to a file in %temp% if you need the output...
Pawel#
They didn't. I use Win8.1 and it definitely doesn't work.
That idea with redirection can be done, however in my project it has no sense, as I want to display just few strings...
Anyway, thanks for help. I am afraid, we will have to wait to Win8.2 to fix that issue.
-Pawel