Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi How to retrieve all parameters as single string

application1 runs another application2 with 2 parameters eg: (NOTE: application1 is not my program)

application2.exe -d:C:\Program Files\app folder -z:Folder menu\app icons

Problem is... quotes somehow disappeared so instead of 2 parameters application2 will get 5 parameters

Param1=-d:C:\Program
Param2=Files\app
Param3=folder
Param4=-z:Folder menu\app
Param5=app icons

Is there way to retrieve all parameters as single string?

I tried combine parameters in loop

for i:=1 to ParamCount do
parameters=parameters+' '+ParamStr(i);

but it is not good solution, because path can contain also double or triple spaces eg.

Program files\app   folder\ 

cmd.exe can capture all parameters in %* , but it gives wrong results if parameter contains special characters like ^^~@@&& ...

like image 918
Nafalem Avatar asked Aug 14 '14 17:08

Nafalem


1 Answers

Call the Windows API function GetCommandLine to retrieve the original command line.

var
  CmdLine: string;
....
CmdLine := GetCommandLine;

You'd better hope that you never need to work with a file whose name contains a dash following a space! Trying to persuade the author of the other application to fix their programming would be prudent.

like image 160
David Heffernan Avatar answered Nov 03 '22 01:11

David Heffernan