Hello, I build a program, and in my program I try to execute a file Test.sh, but the file Test.sh doesn't execute, the program doesn't have any exception, the file Test.sh has permission of execution, when I execute the file Test.sh works okay form Terminal , here is my code:
unit untFrmTest;
{$mode objfpc}{$H+}
interface
uses
Messages, SysUtils, FileUtil, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids, Buttons, ExtCtrls, Process,
{$IFDEF WIN32}
Windows, ShellApi,
{$ENDIF}
StrUtils;
type
{ TFrmTest}
TFrmTest = class(TForm)
CmdNext: TBitBtn;
CmdPrior: TBitBtn;
procedure CmdNextClick(Sender: TObject);
procedure CmdPriorClick(Sender: TObject);
procedure FormShow(Sender: TObject);
private
{ private declarations }
StrCount: String;
procedure ExecuteAppSh(StrFileName: string; StrParameter: string);
public
{ public declarations }
end;
var
FrmTest: TFrmTest;
implementation
{$R *.lfm}
{ TFrmTest }
procedure TFrmTest.ExecuteAppSh(StrFileName: string; StrParameter: string);
var
StrPathApp: string;
begin
with TProcess.Create(nil) do try
StrPathApp := StrFileName + ' ' + StrParameter;
CommandLine := StrPathApp;
Options := [poNoConsole, poUsePipes];
Execute;
except
on ErrHandle: Exception Do
begin
ShowMessage(ErrHandle.Message);
end;
end;
end;
procedure TFrmTest.FormShow(Sender: TObject);
begin
FrmTest.Visible:=true;
end;
procedure TFrmTest.CmdNextClick(Sender: TObject);
begin
StrCount := '1';
ExecuteAppSh('./Test.sh', StrCount);
end;
procedure TFrmTest.CmdPriorClick(Sender: TObject);
begin
StrCount := '2';
ExecuteAppSh('./Test.sh', StrCount);
end;
end.
File: Test.sh
#./bin/bash
case $1 in
1) chmod 644 test.txt;;
2) echo "Hello World 2";;
esac
Lazarus version 0.9.30.4, Linux Ubuntu version 12.04, please if somebody can help me, thanks in advance.