I use Delphi 7 IDE. I want to run .exe from the command line with parameters (to be defined).
- How can I know if my app is running with the CMD command?
- How can I read the parameter with source code?
I use Delphi 7 IDE. I want to run .exe from the command line with parameters (to be defined).
On
var
bHideForm = boolean ;
begin
bHideForm := False;
bHideForm := ParamCount > 0;
if bHideForm then
bMetadataExport := GetParamValue(C_MENU, sMetaDataMenu);
{--------------------- function GetParamValue ----------------------------- }
function GetParamValue(aParamName: string; out oParamValue: string): Boolean;
var
i: Integer;
s: string;
begin
Result := False;
for i := 1 to ParamCount do
begin
s := ParamStr(i);
Result := pos(aParamName, UpperCase(s)) = 1;
if Result then
begin
oParamValue := copy(s, length(aParamName)+2, MaxInt);
Exit;
end;
end;
end;
end;
You can't, nor do you ever need to. If your project is a console app, then the
.exeis always run inside of a console window process. If the project is not a console app, then there is no console, but you can create one if needed usingAllocConsole(). Any process, whether it is a console app or not, can receive command-line parameter, though.Use the
ParamCount()andParamStr()functions in theSystemunit, or theFindCmdLineSwitch()function in theSysUtilsunit.Or, use
GetCommandLine()in theWindowsunit and parse the raw command-line data yourself.