Page 1 of 1
Windows console with UNICODE [Resolved]
Posted: Thu May 11, 2017 3:01 pm
by Kwai chang caine
Hello at all
I try to use this nice code of NETMAESTRO
http://www.purebasic.fr/english/viewtop ... 56#p185756
Code: Select all
prog$ = "cmd.exe"
dosbox = RunProgram(prog$, "", "", #PB_Program_Open|#PB_Program_Read|#PB_Program_Write|#PB_Program_Hide|#PB_Program_Ascii)
If dosbox
OpenWindow(0,0,0,400,500,"Results from DosBox",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
StartDrawing(WindowOutput(0))
DrawText(65,200, "Pinging now, Stand by for results...", #Black, GetSysColor_(#COLOR_BTNFACE))
StopDrawing()
NewList results.s()
WriteProgramStringN(dosbox, "ping google.com", #PB_Ascii)
WriteProgramData(dosbox, #PB_Program_Eof, 0)
While ProgramRunning(dosbox)
If AvailableProgramOutput(dosbox)
AddElement(results())
results() = ReadProgramString(dosbox, #PB_Ascii)
Else
Delay(1)
EndIf
Wend
AddElement(results())
AddElement(results())
results() = "Program finished with exit code = " + Str(ProgramExitCode(dosbox))
CloseProgram(dosbox)
ListViewGadget(0,0,0,400,500)
ForEach results()
AddGadgetItem(0, -1, results())
Next
Repeat:Until WaitWindowEvent()=#WM_CLOSE
Else
MessageRequester("OOPS!", "Can't find " + prog$ )
EndIf
And i obtain this sentence
D‚lai d'attente de la demande d‚pass‚.
instead of
Délai d'attente de la demande dépassé.
I have adding #PB_ASCII everywhere without success, if someone understand why
Have a good day
Re: Windows console with UNICODE
Posted: Thu May 11, 2017 4:11 pm
by fryquez
Cmd.exe does not put out Ascii, but OEM.
Quick and dirrty example.
Code: Select all
prog$ = "cmd.exe"
dosbox = RunProgram(prog$, "", "", #PB_Program_Open|#PB_Program_Read|#PB_Program_Write|#PB_Program_Hide|#PB_Program_Ascii)
If dosbox
OpenWindow(0,0,0,400,500,"Results from DosBox",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
StartDrawing(WindowOutput(0))
DrawText(65,200, "Pinging now, Stand by for results...", #Black, GetSysColor_(#COLOR_BTNFACE))
StopDrawing()
NewList results.s()
WriteProgramStringN(dosbox, "ping google.com", #PB_Ascii)
WriteProgramData(dosbox, #PB_Program_Eof, 0)
While ProgramRunning(dosbox)
If AvailableProgramOutput(dosbox)
AddElement(results())
sOEM_in_unicode.s = ReadProgramString(dosbox, #PB_Ascii)
iByteLength = Len(sOEM_in_unicode) + 2
sOem_in_Ascii.s = Space(iByteLength)
PokeS(@sOem_in_Ascii, sOEM_in_unicode, -1, #PB_Ascii)
sunicode.s = Space(iByteLength)
OemToChar_(@sOem_in_Ascii, @sunicode)
results() = sunicode
Else
Delay(1)
EndIf
Wend
AddElement(results())
AddElement(results())
results() = "Program finished with exit code = " + Str(ProgramExitCode(dosbox))
CloseProgram(dosbox)
ListViewGadget(0,0,0,400,500)
ForEach results()
AddGadgetItem(0, -1, results())
Next
Repeat:Until WaitWindowEvent()=#WM_CLOSE
Else
MessageRequester("OOPS!", "Can't find " + prog$ )
EndIf
Re: Windows console with UNICODE
Posted: Thu May 11, 2017 4:20 pm
by netmaestro
You could try this:
Code: Select all
prog$ = "cmd.exe"
dosbox = RunProgram(prog$, "", "", #PB_Program_Open|#PB_Program_Read|#PB_Program_Write|#PB_Program_Hide|#PB_Program_Ascii)
If dosbox
OpenWindow(0,0,0,400,500,"Results from DosBox",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
StartDrawing(WindowOutput(0))
DrawText(65,200, "Pinging now, Stand by for results...", #Black, GetSysColor_(#COLOR_BTNFACE))
StopDrawing()
NewList results.s()
WriteProgramStringN(dosbox, "chcp 65001", #PB_Ascii) ;<------------------- Added line
WriteProgramStringN(dosbox, "ping google.com", #PB_Ascii)
WriteProgramData(dosbox, #PB_Program_Eof, 0)
While ProgramRunning(dosbox)
If AvailableProgramOutput(dosbox)
AddElement(results())
results() = ReadProgramString(dosbox, #PB_Ascii)
Else
Delay(1)
EndIf
Wend
AddElement(results())
AddElement(results())
results() = "Program finished with exit code = " + Str(ProgramExitCode(dosbox))
CloseProgram(dosbox)
ListViewGadget(0,0,0,400,500)
ForEach results()
AddGadgetItem(0, -1, results())
Next
Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow ;<---------------------- Fixed line
Else
MessageRequester("OOPS!", "Can't find " + prog$ )
EndIf
Re: Windows console with UNICODE
Posted: Thu May 11, 2017 4:25 pm
by Kwai chang caine
Hello MASTER of the net, always glad to read you
Excuse me for ask this style of question ,i know it's very hard for you all not french, for test this style of problem

You have so much chance to not have in your english langage this
@#£$@ of french shit characters
I have try your new code and i have always problem
R‚ponse de 163.95.16.2ÿ: Impossible de joindre l'h“te de destination.
Edit
Excuse me FRYQUEZ, you have sending your answer in the same time of NETMAESTRO, and i not see it
First ...hello at you too
Your code works !!!
Re: Windows console with UNICODE
Posted: Thu May 11, 2017 4:28 pm
by Kwai chang caine
Thanks a lot at you two for your quick answers 
Have a very good day at you two
Re: Windows console with UNICODE [Resolved]
Posted: Thu May 11, 2017 4:33 pm
by fryquez
Hi KCC,
I wonder does netmaestro's new code works for you, if you change the following line.
Code: Select all
results() = ReadProgramString(dosbox, #PB_Ascii)
to
Code: Select all
results() = ReadProgramString(dosbox, #PB_UTF8)
Re: Windows console with UNICODE [Resolved]
Posted: Thu May 11, 2017 4:40 pm
by Kwai chang caine
No, i have replace, like you say
Code: Select all
results() = ReadProgramString(dosbox, #PB_Ascii)
to
Code: Select all
results() = ReadProgramString(dosbox, #PB_UTF8)
in the two codes of NETMAESTRO and that not works
Only your code works
But please MASTER.....don't ask to me, why

Re: Windows console with UNICODE [Resolved]
Posted: Thu May 11, 2017 6:29 pm
by Olliv
This problem was evocated on french forum. Before Fred removed the half part of messages, the topic contained 14 pages not to really have the good answer.
I decided finally to remake a homebuild console with a cross-platform font named "Lucida console" to answer the better possible to the question.
Not easy... Thanks to Fryquez.
Re: Windows console with UNICODE [Resolved]
Posted: Fri May 12, 2017 8:53 am
by ChrisR
I think we know each other fryquez
Nice to see you
Always on top, thanks for the solution for this cmd headache.
Re: Windows console with UNICODE [Resolved]
Posted: Fri May 12, 2017 11:20 am
by fryquez
Hi Chris, It's been a while. Happy to see you again.

Re: Windows console with UNICODE [Resolved]
Posted: Fri May 12, 2017 11:50 am
by ChrisR
Hi fryquez
Yeah, a little while, sorry for that

but I needed a break to try to regain some motivation.
But here or elsewhere, the concern is the same for me, free time is no longer the one I have had.
Take care