-1

I want to open a program with below code but I can't

program launchprogram;
uses 
  Classes, SysUtils, Process;
var 
  AProcess: TProcess;
begin
  AProcess := TProcess.Create(nil);
  AProcess.Executable:= 'C:\Program Files (x86)\oCam\oCam.exe';
  AProcess.Parameters.Add('-h');
  AProcess.Options := AProcess.Options + [poWaitOnExit];
  AProcess.Execute;
  AProcess.Free;
end.

How can I solve this problem?

Rudy Velthuis
  • 28,387
  • 5
  • 46
  • 94
mohsen.2
  • 91
  • 1
  • 2
  • 6
  • 3
    Please tell us more about "_but I can't_" and also about "_this problem_". Be more outspoken! ;o) At the first glance all correct. The program works fine at least for `AProcess.Executable:= 'regedit'; AProcess.Parameters.Add('/?');` – Abelisto Jul 10 '16 at 14:39
  • Are you sure your Executable string is correct? – Rudy Velthuis Jul 10 '16 at 15:06
  • This is a very poorly written question. What does `oCam.exe` do? What results were you expecting and exactly what did you observe? – lurker Jul 10 '16 at 18:10
  • I assume that oCam.exe is supposed to show a few lines of help. OCam is a screen capture tool, like e.g. Camtasia. – Rudy Velthuis Jul 10 '16 at 19:03
  • Then maybe requirement for elevation causes problems. – Marco van de Voort Jul 11 '16 at 08:10

2 Answers2

0

See: http://wiki.freepascal.org/Executing_External_Programs

I tried this on a linux machine and it works fine

SysUtils.ExecuteProcess(UTF8ToSys('/full/path/to/binary'), '', []);  

or better:

SysUtils.ExecuteProcess(UTF8ToAnsi('/full/path/to/binary'), '', []);

It is also supposed to work in MSWin

Ahmad Aghazadeh
  • 16,571
  • 12
  • 101
  • 98
Middlecope
  • 21
  • 2
0

Here is an example of the use of TProcess on a linux machine: enter code here


    procedure TForm1.Button1Click(Sender: TObject);
    VAR AProcess : TProcess;
    begin
     AProcess:= TProcess.Create(nil);
     Aprocess.Executable:= '/usr/bin/mysqldump';
     Aprocess.Parameters.Add('--user=root');
     Aprocess.Parameters.Add('--password=any');
     Aprocess.Parameters.Add('--result-file=/home/user/mydump.sql;
     Aprocess.Parameters.Add('database1);
     AProcess.Options := AProcess.Options + [poWaitOnExit,poUsePipes];
     AProcess.Execute;
     AProcess.Free;
     end; 
hope this will help you. I think the executable is not wright
Middlecope
  • 21
  • 2