Forum > General

TProcess ExitCode?

(1/3) > >>

Чебурашка:
Hello,
under Linux, using this (bash) script with 755 permissions:


--- Code: Text  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---#!/bin/bash echo "Input: $1";exit $1;  
if I execute in a console:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- $ ./test-script.sh 0;Input: 0$ echo $?;0$ ./test-script.sh 1;Input: 1$ echo $?;1$ bash test-script.sh 0;Input: 0$ echo $?;0$ bash test-script.sh 1;Input: 1$ echo $?;1  
but if I run the following program:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program project1; uses  SysUtils, process; var  p: TProcess;begin  p := TProcess.Create(nil);  try        p.Executable := './test-script.sh';    p.Options := [TProcessOption.poWaitOnExit];        p.Parameters.Add('');         p.Parameters[0] := '0';     p.Execute();    Writeln(Format('Exit code: %d', [p.ExitCode]));        p.Parameters[0] := '1';     p.Execute();    Writeln(Format('Exit code: %d', [p.ExitCode]));            finally    FreeAndNil(p);        end;   p := TProcess.Create(nil);  try        p.Executable := '/bin/bash';    p.Options := [TProcessOption.poWaitOnExit];        p.Parameters.Add('test-script.sh');     p.Parameters.Add('');         p.Parameters[1] := '0';     p.Execute();    Writeln(Format('Exit code: %d', [p.ExitCode]));        p.Parameters[1] := '1';     p.Execute();    Writeln(Format('Exit code: %d', [p.ExitCode]));      finally    FreeAndNil(p);  end;end. 
the result is:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---$ ./project1 Input: 0Exit code: 0Input: 1Exit code: 0Input: 0Exit code: 0Input: 1Exit code: 0 
Is this correct? What am I missing in TProcess usage?

Чебурашка:
Update:

if I ask for
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---ExitStatus instead of
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---ExitCode output becomes


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---$ ./project1 Input: 0Exit code: 0Input: 1Exit code: 1Input: 0Exit code: 0Input: 1Exit code: 1 
Probably just the name ExitStatus refers to the linux exit code of the programs.

zeljko:
https://www.freepascal.org/docs-html/fcl/process/tprocess.exitcode.html

Чебурашка:

--- Quote from: zeljko on November 17, 2024, 10:08:53 am ---https://www.freepascal.org/docs-html/fcl/process/tprocess.exitcode.html

--- End quote ---

Thanks, I read the docs before posting here.
In the case of a process that terminates on it's own, ExitStatus is said has to coincide with ExitCode, but my examples seems is the opposite. I miss something for sure.

zeljko:
But it says that on unix status code can be different than exit code.

Navigation

[0] Message Index

[#] Next page

Go to full version