-2

How do I run an external application with Free Pascal/Lazarus (using Windows)? I found the "official" reference page, with several implementations and examples. Although I'm sure it works for many people, I, with my current knowledge level, am some what lost (I don't have much routine programming with Free Pascal yet, and other examples I found on the web didn't work for me).

Is there a "clear" example that helps me to do the "first steps"? Thanks.

Albin
  • 1,000
  • 1
  • 11
  • 33
  • This sort of question adds nothing to the site. All you had to do was try a bit harder. Don't spend 5 minutes, give up and ask here. Programming is hard. You need to invest time and effort. – David Heffernan Aug 07 '18 at 17:58
  • The answer is right there in the documentation that you linked to!! – David Heffernan Aug 07 '18 at 18:25
  • The code in your answer can be found in that documentation, plus lots more useful information, clearly written. I've said all I want to. – David Heffernan Aug 07 '18 at 18:41
  • I didn't understand the example in the reference. So unlike for you, it wasn't "clearly enough" for me, hence the reason for my question. And it's "all the other information" that got me confused in the first place. – Albin Aug 07 '18 at 18:52
  • The example in the docs is exactly the same as the code in your answer! – David Heffernan Aug 07 '18 at 18:59
  • @DavidHeffernan Yes essentially it does. But at the time of writing the question for whatever reason I didn't understand it (now I do). The example I linked to in my answer worked better for me to get an first understanding, from there it was much easier to work with the reference page. So from you're point of view the example in the reference page might be better (having my current level of knowledge I would prefere it myself), but for me the "simple" example, or whatever you want to call it, worked much better for the level of knowledge I had back then. – Albin Aug 08 '18 at 09:06
  • What didn't work in which way? – Marco van de Voort Aug 08 '18 at 10:20
  • @MarcovandeVoort I didn't find a good "entry point" to produce a working example. The reference page hast just too much information. I needed a small/simple "working example" I can warp my head around. Once I had it, it was much easier to start working with the reference page... (just the way "my thinking" works, I suppose...) Thanks for you're example by the way, that is even simpler... – Albin Aug 09 '18 at 15:45
  • As answer already states ("if you don't need piping"), there are simply differing scenarios. Anyway, I'm glad it's solved. – Marco van de Voort Aug 10 '18 at 09:08

2 Answers2

2

If you don't need piping you can just use execute process.

uses sysutils;
begin
  executeprocess('notepad.exe',['document.txt']);
end.
Marco van de Voort
  • 25,628
  • 5
  • 56
  • 89
-1

Here's a working example (source) using TProcess:

uses Process;
var
  RunProgram: TProcess;
begin
  RunProgram := TProcess.Create(nil);
  RunProgram.CommandLine := ‘Path and Name of Program’;
  RunProgram.Execute;
  RunProgram.Free;
end;

For example, this will open the application "MS Notepad":

uses Process;
var
  RunProgram: TProcess;
begin
  RunProgram := TProcess.Create(nil);
  RunProgram.CommandLine := ‘notepad.exe’;
  RunProgram.Execute;
  RunProgram.Free;
end;
Albin
  • 1,000
  • 1
  • 11
  • 33
  • For simple stuff I'd recommend using executeprocess and TPRocess wrapper Runcommnad as muhc a possible. – Marco van de Voort Aug 09 '21 at 05:37
  • @MarcovandeVoort you mean according to your "old" answer? It might be nice for other users if you could explain a little about the advantages/disadvantages of either method... – Albin Aug 09 '21 at 06:05
  • See the wiki referenced in the question, I updated that a few years ago to steer people away from naieve experimentation with tprocess if not necessary. – Marco van de Voort Aug 09 '21 at 07:21