a @comspec dir replies a ', so that I even cant capture the character for a workaround in the oem2ansi function (e.g. with stringinstr).... it's also related to this discussion....
In the SmOke_N version the problem with DOS 'foreign' chars is simply due to DOS using OEM codepage.
So the solution is simple. Translate filenames from Oem To Ansi.
Maybe there is a way to switch the codepage used before execution?
This post will be edited again by Polyphem: Tomorrow, 11:55 AM
Took quiet some time to find a working piece of code for this one , no worries, didnt search fulltime ...
AutoIt
#include"Constants.au3"; create a file "äßöüßü^.txt" in the script root... notice the difference in the msgbox regarding the output of ; in the OEM2ANSI version the output for is '; in the CHCP1252 version the output for is ;; of course the codepage can be set to anything you need : ).... reference for windows codepages can be found here <a href='http://www.microsoft.com/globaldev/reference/cphome.mspx' class='bbc_url' title='External link' rel='nofollow external'>http://www.microsoft.com/globaldev/reference/cphome.mspx</a>;---------------------------------------- @ComSpec with _OEM2ANSI ---------------------------------$line=""$foo=Run(@ComSpec&" /c dir","",@SW_HIDE,$STDERR_CHILD+$STDOUT_CHILD)While1$line&=StdoutRead($foo)If@errorThenExitLoopWend$output_comspec_oem2ansi=_OEM2ANSI($line);---------------------------------------- @ComSpec with chcp 1252 ---------------------------------$line=""$foo=Run(@ComSpec,"",@SW_HIDE,$STDIN_CHILD+$STDOUT_CHILD)StdinWrite($foo,"chcp 1252"&@CRLF); change codepage for cmd.exe instance to 1252 (West European Latin)StdinWrite($foo,"dir"&@CRLF)StdinWrite($foo,"exit"&@CRLF); send exit command to trigger stdoutWhile1$line&=StdoutRead($foo)If@errorThenExitLoopWend$keyword_dir=stringinstr($line,">dir")+6; to purge the output of the "chcp 1252" command$keyword_colon=stringinstr($line,":",0,-1)-5; to purge the output of the "exit" command$line=StringMid($line,$keyword_dir,stringlen($line)-(stringlen($line)-$keyword_colon)-$keyword_dir)$output_comspec_chcp1252=$line;---------------------------------------- Output ---------------------------------MsgBox(0,"Stdout OEM2ANSI",$output_comspec_oem2ansi)MsgBox(0,"Stdout chcp 1252",$output_comspec_chcp1252)Exit;---------------------------------------- Func ---------------------------------Func_OEM2ANSI($what)$ret=DllCall('user32.dll','Int','OemToChar','str',$what,'str','')Return$ret[2]EndFunc;==>_OEM2ANSI
For me it works fine this way. Anyone got reasons why not to use Codepage 1252? Though I fear it would only work for Western Code. Any comments are welcome...
Cheers
Edited by Polyphem, 05 September 2008 - 05:56 PM.
This post will be edited again by Polyphem: Tomorrow, 11:55 AM
Took quiet some time to find a working piece of code for this one , no worries, didnt search fulltime ...
AutoIt
#include"Constants.au3"; create a file "äßöüßü^.txt" in the script root... notice the difference in the msgbox regarding the output of ; in the OEM2ANSI version the output for is '; in the CHCP1252 version the output for is ;; of course the codepage can be set to anything you need : ).... reference for windows codepages can be found here http://www.microsoft.com/globaldev/reference/cphome.mspx;---------------------------------------- @ComSpec with _OEM2ANSI ---------------------------------$line=""$foo=Run(@ComSpec&" /c dir","",@SW_HIDE,$STDERR_CHILD+$STDOUT_CHILD)While1$line&=StdoutRead($foo)If@errorThenExitLoopWend$output_comspec_oem2ansi=_OEM2ANSI($line);---------------------------------------- @ComSpec with chcp 1252 ---------------------------------$line=""$foo=Run(@ComSpec,"",@SW_HIDE,$STDIN_CHILD+$STDOUT_CHILD)StdinWrite($foo,"chcp 1252"&@CRLF); change codepage for cmd.exe instance to 1252 (West European Latin)StdinWrite($foo,"dir"&@CRLF)StdinWrite($foo,"exit"&@CRLF); send exit command to trigger stdoutWhile1$line&=StdoutRead($foo)If@errorThenExitLoopWend$keyword_dir=stringinstr($line,">dir")+6; to purge the output of the "chcp 1252" command$keyword_colon=stringinstr($line,":",0,-1)-5; to purge the output of the "exit" command$line=StringMid($line,$keyword_dir,stringlen($line)-(stringlen($line)-$keyword_colon)-$keyword_dir)$output_comspec_chcp1252=$line;---------------------------------------- Output ---------------------------------MsgBox(0,"Stdout OEM2ANSI",$output_comspec_oem2ansi)MsgBox(0,"Stdout chcp 1252",$output_comspec_chcp1252)Exit;---------------------------------------- Func ---------------------------------Func_OEM2ANSI($what)$ret=DllCall('user32.dll','Int','OemToChar','str',$what,'str','')Return$ret[2]EndFunc;==>_OEM2ANSI
For me it works fine this way. Anyone got reasons why not to use Codepage 1252? Though I fear it would only work for Western Code. Any comments are welcome...