PDA

View Full Version : running an outside program regardless of error....



edexter
09-10-2007, 01:03 PM
I am trying to embed python in free pascal and have partialy succeeded. because I couldn't answer the question why it is realy a c command line program that can be called from pascal... The problem I am having is that it will run in c and give me an error but the code executes and gives me a file... when I run it from free pascal it tells me there is an error and doesn't run the python file... The code I used to call the program is a modified version of what is on the wiki. Is there a way to get this to function the same and allow the c program to generate the error instead of stopping??

// This is a demo program that shows how to launch
// an external program.
// program launchprogram;
unit launchprogram;

interface

procedure runprogram(name :string);
// Here we include files that have useful functions
// and procedures we will need.
// uses
// Classes, SysUtils, Process;

// This is defining the var "AProcess" as a variable
// of the type "TProcess"
//var
// AProcess: TProcess;
implementation
uses
Classes, SysUtils, Process;

// This is where our program starts to run
procedure runprogram(name :string);
var
AProcess: TProcess;
begin;
// Now we will create the TProcess object, and
// assign it to the var AProcess.
AProcess := TProcess.Create(nil);

// Tell the new AProcess what the command to execute is.
// Let's use the FreePascal compiler
AProcess.CommandLine := name; //'ppc386 -h';

// We will define an option for when the program
// is run. This option will make sure that our program
// does not continue until the program we will launch
// has stopped running. vvvvvvvvvvvvvv
AProcess.Options := AProcess.Options + [poWaitOnExit];

// Now that AProcess knows what the commandline is
// we will run it.
AProcess.Execute;

// This is not reached until ppc386 stops running.
AProcess.Free;
end;
end.