Hi,
I want to run a process from within a console app on Linux. Is this correct ?
var aArguments := new ImmutableList<String>(['-H']);
var p := new Process;
p.Arguments := aArguments;
p.Command := 'hostname';
try
p.Start;
p.WaitFor;
except
on e: Exception do
begin
writeLn(e.Message);
end;
end;
It got past the waitfor on darwin but I get an exception on linux show inside the debug window of Fire.
!> Fatal exception of type RemObjects.Elements.System.Exception on thread 25E2
!> Message: Array index 1 is outside of the valid range (0..0)
For one, pretty sure you’ll want/need a full path for Command, as a Process doesn’t go thru the shell, and the shell is what lets you magically find executables via search paths, just by name.
So you;ll want
p.Command := '/bin/hostname'
or wherever Linux has that one. That said, the error sounds wrong, so i’ll have a look…
var aArguments := new ImmutableList<String>([]);
var p := new Process();
p.Arguments := aArguments;
p.Command := '/bin/hostname';
p.RedirectOutput := true;
p.Start;
p.WaitFor;
var aStdOut := p.StandardOutput;
var aStdErr := p.StandardError;
if(p.ExitCode = 0)then
begin
var value := p.StandardOutput;
writeLn(value);
end;
With my code on darwin I get a segmentation fault when I add the redirectoutput := true.
IN the debugger it displays the output what Im assuming is the actual hostname command but it seems to hang and never gets to the check on exitcode