I'm trying to use german characters like "ö,a,ü" in combination with TProcess
within the CommandLine
parameter. More specifically I'm trying to open an Explorer window that shows a folder which includes the characters in it's name/path. Here's the code:
strFolderPath := '"C:\FolderName_Ä"'
RunProgram := TProcess.Create(nil);
RunProgram.CommandLine := 'C:\Windows\explorer.exe ' + strFolderPath;
RunProgram.Execute;
RunProgram.Free;
Apparently using ü/ä/ö in the CommandLine
Property doesn't work. Which way can I use to encode them properly within the string?
It works for me if I convert to strFolderpath (which is probably UTF8 if your program is developed with Lazarus) to 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;
Note also that the TProcess.CommandLine is deprecated. The recommended way is to put the binary into TProcess.Executable and add the parameters, one by one, by TProcess.Parameters.Add(...).