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?
CodePudding user response:
How can I know if my app is running with the CMD command?
You can't, nor do you ever need to. If your project is a console app, then the .exe
is 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 using AllocConsole()
. Any process, whether it is a console app or not, can receive command-line parameter, though.
How can I read the parameter with source code?
Use the ParamCount()
and ParamStr()
functions in the System
unit, or the FindCmdLineSwitch()
function in the SysUtils
unit.
Or, use GetCommandLine()
in the Windows
unit and parse the raw command-line data yourself.