Buongiorno, devo creare un applicazione sotto Linux la quale arrivata a un certo punto deve avviare uno script bash, ma purtroppo quando si avvia lo script la mia applicazione si freeza e non consente di fare nulla, terminato lo script l'applicazione riprende a funzionare normalmente.
ho usato:
- Executeprocess
- TProcess
- RunCommand (quest'ultimo è più appropriato perché consente di visualizzare un output dello script)
RunCommand(directory + 'flash.sh', ['/ s' , '/ t' , '0' ],s);
Come potrei risolvere?
Grazie mille
Questa l'ho fata anni fa', e fa proprio quello che ti serve:
{Eseguo un comando senza aspettare che termini}
procedure EseguiSenzaAspettare(const Comando, Parametri:string;Visualizza:Boolean;
ForzaDirCorrente:String = '');
var MyProcess:TProcess;
Appo:Integer;
AppoStr:String;
begin
MyProcess:=TProcess.Create(nil);
MyProcess.Priority:=ImpostaPriorProcesso;
MyProcess.CommandLine:=Comando + ' ' + Parametri;
AppoStr:=MyProcess.CommandLine;
if (ForzaDirCorrente = '') then begin
MyProcess.CurrentDirectory:=AppendPathDelim(ExtractFileDir(Comando));
end else begin
MyProcess.CurrentDirectory:=AppendPathDelim(ForzaDirCorrente);
end;
if Visualizza then MyProcess.ShowWindow:=swoShow
else MyProcess.ShowWindow:=swoHIDE;
MyProcess.Priority:=ppNormal;
try
MyProcess.Execute;
finally
Sleep(500); //Per assicurarmi che l'eseguibile sia stato lanciato
Appo:=MyProcess.ExitStatus;
Appo:=MyProcess.ExitCode;
FreeAndNil(MyProcess);
end;
end;
Ciao, Mario
L'applicazione deve andare avanti indipendentemente dall'esecuzione dello script
ho già guardato il wiki ma non trovato risposte al mio problema
dovresti indicare nelle opzioni che il tuo programma non deve attendere il termine del processo
AProcess.Options := AProcess.Options - [poWaitOnExit];
Allora, partiamo dal primo link che ti avevo mandato giorni fa':
https://wiki.freepascal.org/Executing_External_Programs
Ad un certo punto, dove parla di TProcess, c'è del codice:
// This is a demo program that shows
// how to launch an external program.
program launchprogram;
// Here we include files that have useful functions
// and procedures we will need.
uses
Classes, SysUtils, Process;
// This defines the var "AProcess" as a variable
// of the type "TProcess"
var
AProcess: TProcess;
// This is where our program starts to run
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 Free Pascal compiler (i386 version that is)
AProcess.Executable:= 'ppc386';
// Pass -h together with ppc386 so actually 'ppc386 -h' is executed:
AProcess.Parameters.Add('-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 let AProcess run the program
AProcess.Execute;
// This is not reached until ppc386 stops running.
AProcess.Free;
end.
Se disattivi questa riga, ottieni proprio quello che vuoi:
AProcess.Options := AProcess.Options + [poWaitOnExit];
Ciao, Mario