PDA

View Full Version : POpen



edexter
28-09-2007, 10:47 PM
I would like to run a simple command line program with popen (unless there is a better option)... I seem to be getting lost in the examples because they always define something as text and what I want is binary (or I am having trouble understanding why they are defining text). ... what I want to run is something like


empython programname functionname

(I compiled a c example from python)

edexter
04-10-2007, 11:41 PM
I answered my own question... python uses popen (c varients cross platform) and free pascal uses a different method... This is modified from the wiki to execute a program (and is free pascal only)..



// 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.

NecroDOME
05-10-2007, 06:27 AM
You can try ShellExecute, uses ShellAPI. (google for "ShellExecute Delphi", lots and lots of references!)