Page 1 of 1

Diacritic characters and shell CMD

Posted: Sun Jun 12, 2011 1:49 pm
by Kangaroo SW
For a project I need to get the "Computername" of a Windows PC I use the shell CMD, but if the computername contains non ASCII chars (umlautes) I get odd characters displayed in within LiveCode.

Also, the global variable (%Computername%) from inside LiveCode does
not display non ASCII chars correctly and respects only uppercase so I can not use it.

So I try to use the CMD shell with the command "hostname", which
displays the name correctly in the commandline window but not inside LiveCode.

I made a little script wich replaces the odd chars but there must be a better way !
After reading the use-list and the Forum up and down I have give up :oops: , can anyone help :lol: ?

Code: Select all

on mouseUp
   set hideConsoleWindows to true
   put empty into varComputerName
   
   --••  use the shell to get the computername, this returns Ԑ·Š‚…™šŽ”„ for ÈÉÀèéàÖÜÄöüä
   put shell("hostname") into varComputerName
   
   --••  replace chars to get the correct characters
   replace "Ô" with "È" in varComputerName
   replace "" with "É" in varComputerName
   replace "·" with "À" in varComputerName
   
   replace "Š" with "è" in varComputerName
   replace "‚" with "é" in varComputerName
   replace "…" with "à" in varComputerName
   
   replace "™" with "Ö" in varComputerName
   replace "š" with "Ü" in varComputerName
   replace "Ž" with "Ä" in varComputerName
   
   replace "”" with "ö" in varComputerName
   replace "" with "ü" in varComputerName
   replace "„" with "ä" in varComputerName
   
   answer varComputerName
end mouseUp


Cheers Rolf

Re: Diacritic characters and shell CMD

Posted: Sun Jun 12, 2011 3:48 pm
by Klaus
Hi Rolf,

well, the problem is the non-standard character encoding of the Windows shell (no surprise really :D )
Unfortunately I have no idea wha encoding is being used here, at least this is obviously not standard LATIN-ISO-whatever!


Best

Klaus

Re: Diacritic characters and shell CMD

Posted: Sun Jun 12, 2011 5:00 pm
by shaosean
This is an interesting read and may help you out, but remember that Rev does not handle Unicode all that well (at all?) coming from the OS (for example file paths)..

http://stackoverflow.com/questions/1259 ... -exe-using

Re: Diacritic characters and shell CMD

Posted: Sun Jun 12, 2011 7:29 pm
by Kangaroo SW
Thank's Klaus and shaosean

This means that my poor mans handler will be the only solution to my problem, for now :roll: ?!

Or is there an other way to get the computername in Windows ?

Cheers
Rolf

Re: Diacritic characters and shell CMD

Posted: Mon Jun 13, 2011 1:05 am
by shaosean
You could always build an external, but you would have the same issue as Rev does not handle Unicode there either..

Re: Diacritic characters and shell CMD

Posted: Mon Jun 13, 2011 9:19 pm
by RRobert
You could query HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName.

Robert