Recent

Author Topic: Execute another program  (Read 5368 times)

Relative

  • Jr. Member
  • **
  • Posts: 56
  • Sedo est anima rerum.
    • FxCoder
Execute another program
« on: February 01, 2011, 08:48:20 pm »
Hi Coders!

I would like to execute a simple program.

I use this code:

Code: [Select]
program Exe_Execute;
uses
   Classes, SysUtils, Process;
var
   AProcess: TProcess;
begin
   AProcess := TProcess.Create(nil);
   AProcess.CommandLine := 'C:\Users\Lime\Desktop\test.exe';
   AProcess.Options := AProcess.Options + [poWaitOnExit];
   AProcess.Execute;
end.

When I run my Exe_Execute.exe program, it executes the test.exe. But the main program still run. It has a black window like a Command Prompt window. When I close the test.exe, then my Exe_Execute.exe program close too.

Is there any way to run the test.exe, than immediately close my Exe_Execute.exe program before I close the test.exe?

Thank you in advance.

Relative

eny

  • Hero Member
  • *****
  • Posts: 1648
Re: Execute another program
« Reply #1 on: February 01, 2011, 09:11:21 pm »
All posts based on: Win10 (Win64); Lazarus 3_4  (x64) 25-05-2024 (unless specified otherwise...)

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1933
Re: Execute another program
« Reply #2 on: February 01, 2011, 09:12:04 pm »
What do you think the poWaitOnExit option is good for?

http://www.freepascal.org/docs-html/fcl/process/tprocessoptions.html

Relative

  • Jr. Member
  • **
  • Posts: 56
  • Sedo est anima rerum.
    • FxCoder
Re: Execute another program
« Reply #3 on: February 01, 2011, 09:23:32 pm »
Thank you Eny and Theo!

The solution code:

Quote
AProcess.Options := AProcess.Options + [poNewConsole];

 

TinyPortal © 2005-2018