FIX: Process commands with single quotes (fixes #2862)

This commit is contained in:
Alexander Koblov 2026-05-15 17:34:03 +03:00
commit 837cc08394
2 changed files with 11 additions and 11 deletions

View file

@ -30,7 +30,7 @@ unit uOSUtils;
interface
uses
SysUtils, Classes, LCLType, uDrive, DCBasicTypes, uFindEx
SysUtils, Classes, Process, LCLType, uDrive, DCBasicTypes, uFindEx
{$IF DEFINED(UNIX)}
, DCFileAttributes
{$IFDEF DARWIN}
@ -149,9 +149,9 @@ function GetSfxExt: String;
function IsAvailable(Drive: PDrive; TryMount: Boolean = True) : Boolean;
function GetShell : String;
{en
Formats a string which will execute Command via shell.
Formats parameters which will execute Command via shell.
}
function FormatShell(const Command: String): String;
procedure FormatShell(Process: TProcess; const Command: String);
{en
Formats a string which will execute Command in a terminal.
}
@ -605,13 +605,13 @@ begin
end;
{$ENDIF}
function FormatShell(const Command: String): String;
procedure FormatShell(Process: TProcess; const Command: String);
const
EXEC_CMD = {$IF DEFINED(MSWINDOWS)}'/C'{$ELSE}'-c'{$ENDIF};
begin
{$IF DEFINED(UNIX)}
Result := Format('%s -c %s', [GetShell, QuoteSingle(Command)]);
{$ELSEIF DEFINED(MSWINDOWS)}
Result := Format('%s /C %s', [GetShell, QuoteDouble(Command)]);
{$ENDIF}
Process.Executable:= GetShell;
Process.Parameters.Add(EXEC_CMD);
Process.Parameters.Add(Command);
end;
procedure FormatTerminal(var sCmd: String; var sParams: String; bKeepTerminalOpen: tTerminalEndindMode);

View file

@ -487,7 +487,7 @@ type
sShellCmdLine := state.sSubParam + ' > ' + QuoteStr(sTmpFilename);
Process := TProcessUTF8.Create(nil);
try
Process.CommandLine := FormatShell(sShellCmdLine);
FormatShell(Process, sShellCmdLine);
Process.Options := [poNoConsole, poWaitOnExit];
Process.Execute;
finally
@ -958,7 +958,7 @@ begin
sShellCmdLine := Copy(sParams, iStart, iCount) + ' > ' + QuoteStr(sTmpFile);
Process := TProcessUTF8.Create(nil);
try
Process.CommandLine := FormatShell(sShellCmdLine);
FormatShell(Process, sShellCmdLine);
Process.CurrentDirectory := sWorkPath;
Process.Options := [poWaitOnExit];
Process.ShowWindow := swoHide;