Recent

Author Topic: [SOLVED] Problem when I try to execute.  (Read 2456 times)

Leonor

  • New Member
  • *
  • Posts: 21
[SOLVED] Problem when I try to execute.
« on: September 30, 2013, 04:19:02 pm »
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.
« Last Edit: September 30, 2013, 06:22:33 pm by Leonor »

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Problem when I try to execute.
« Reply #1 on: September 30, 2013, 04:28:46 pm »
what is required to execute the .sh file? in short the sh is a text file that has a number of commands which interpeter is required to convert the text in to actual commends?
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Leonor

  • New Member
  • *
  • Posts: 21
Re: Problem when I try to execute.
« Reply #2 on: September 30, 2013, 05:31:52 pm »
Hello taazz, thank you for reply, I use the shell BASH, I don't know if this answer your question.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Problem when I try to execute.
« Reply #3 on: September 30, 2013, 05:32:47 pm »
Then "bash" should answer your question as well. eg
Code: [Select]
ExecuteAppSh('./bin/bash '+'./Test.sh', StrCount);
« Last Edit: September 30, 2013, 05:35:15 pm by taazz »
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Leonor

  • New Member
  • *
  • Posts: 21
Re: Problem when I try to execute.
« Reply #4 on: September 30, 2013, 06:21:42 pm »
taazz thank you, it works perfectly.

 

TinyPortal © 2005-2018