我正在尝试在TProcess
参数内将德语字符“ö,a,ü”与CommandLine
结合使用。更具体地说,我试图打开一个资源管理器窗口,该窗口显示一个包含名称/路径中的字符的文件夹。这是代码:
strFolderPath := '"C:\FolderName_Ä"'
RunProgram := TProcess.Create(nil);
RunProgram.CommandLine := 'C:\Windows\explorer.exe ' + strFolderPath;
RunProgram.Execute;
RunProgram.Free;
显然在CommandLine
属性中使用ü/ä/ö不起作用。可以使用哪种方法在字符串中正确编码?
答案 0 :(得分:2)
如果我将strFolderpath(如果您的程序是用Lazarus开发的,则可能是UTF8)转换为Ansi,则对我有用:
uses
LazUTF8;
procedure TForm1.Button1Click(Sender: TObject);
var
strFolderPath: String;
P: TProcess;
begin
strFolderPath := UTF8ToWinCP('d:\äöü');
P := TProcess.Create(nil);
P.CommandLine := 'C:\Windows\explorer.exe ' + strFolderPath;
// better:
// P.Executable := 'C:\windows\explorer.exe';
// P.Parameters.Add(strFolderPath);
P.Execute;
P.Free;
end;
还请注意,不建议使用TProcess.CommandLine。推荐的方法是将二进制文件放入TProcess.Executable中,并通过TProcess.Parameters.Add(...)逐一添加参数。
答案 1 :(得分:0)
在当前主干和3.2.x分支中,可以使用来自unicodestring的processunicode单元中的TProcess。
这也适用于没有lazarus或没有lazarus“ utf8hack”的程序