Windows console with UNICODE [Resolved]

Just starting out? Need help? Post your questions and find answers here.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5498
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Windows console with UNICODE [Resolved]

Post 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 :cry:

Have a good day
Last edited by Kwai chang caine on Thu May 11, 2017 4:31 pm, edited 1 time in total.
ImageThe happiness is a road...
Not a destination
fryquez
Enthusiast
Enthusiast
Posts: 391
Joined: Mon Dec 21, 2015 8:12 pm

Re: Windows console with UNICODE

Post 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 
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Windows console with UNICODE

Post 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 
BERESHEIT
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5498
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Windows console with UNICODE

Post by Kwai chang caine »

Hello MASTER of the net, always glad to read you 8)

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 :oops:
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 :oops:

First ...hello at you too :wink:

Your code works !!!
Last edited by Kwai chang caine on Thu May 11, 2017 4:29 pm, edited 2 times in total.
ImageThe happiness is a road...
Not a destination
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5498
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Windows console with UNICODE

Post by Kwai chang caine »

Thanks a lot at you two for your quick answers 8)
Have a very good day at you two
ImageThe happiness is a road...
Not a destination
fryquez
Enthusiast
Enthusiast
Posts: 391
Joined: Mon Dec 21, 2015 8:12 pm

Re: Windows console with UNICODE [Resolved]

Post 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)
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5498
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Windows console with UNICODE [Resolved]

Post 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 :cry:

Only your code works :D
But please MASTER.....don't ask to me, why :lol:
ImageThe happiness is a road...
Not a destination
User avatar
Olliv
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Sep 22, 2009 10:41 pm

Re: Windows console with UNICODE [Resolved]

Post 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.
User avatar
ChrisR
Addict
Addict
Posts: 1471
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: Windows console with UNICODE [Resolved]

Post by ChrisR »

I think we know each other fryquez :wink:
Nice to see you :)
Always on top, thanks for the solution for this cmd headache.
fryquez
Enthusiast
Enthusiast
Posts: 391
Joined: Mon Dec 21, 2015 8:12 pm

Re: Windows console with UNICODE [Resolved]

Post by fryquez »

Hi Chris, It's been a while. Happy to see you again. :D
User avatar
ChrisR
Addict
Addict
Posts: 1471
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: Windows console with UNICODE [Resolved]

Post by ChrisR »

Hi fryquez :D
Yeah, a little while, sorry for that :oops: 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
Post Reply