Mac OS X: Read console app screen with Delphi Firemonkey

  

I’m absolutely new in FM/Macos. I have a console app (not mine) that does some job and shows percentage of the task. What I need:

run that console program with parameters
run that console program hidden
read percentage to show progress bar

On Windows I used pipes and threads (at first, in my new programs I use AttachConsole + ReadConsoleOutputCharacter + Timer . Very handy and simple.)

I could find some sources on embarcadero forum, but it doesn’t seem to read from console screen:

procedure TForm1.runInMacOSX(DosApp:String;List:Tstrings);
var
LArray: array of Pointer;
LArgs: NSArray;
LTask: NSTask;
LPipe: NSPipe;
fileHandler : NSFileHandle;
data : NSData;
nsText : NSString;
teste : Pointer;
begin
LArgs := TNSArray.Create;
setlength(LArray, 3);
LArray[0] := RawStr(‘-param1’);
LArray[1] := RawStr(‘-param2’);
LArray[2] := RawStr(‘-param3’);
LArgs:=TNSArray.Wrap(TNSArray.Alloc.initWithObjects(@(LArray[0]), 3));
LTask := TNSTask.Create;
LPipe := TNSPipe.Create;
fileHandler := TNSFileHandle.Create;
LTask.setLaunchPath(NSStr(‘someapp’));
LTask.setArguments(LArgs);
LTask.setStandardOutput((LPipe as ILocalObject).GetObjectID);
fileHandler := LPipe.fileHandleForReading;
LTask.launch;
LTask.waitUntilExit;
data := TNSData.Create;
data := fileHandler.readDataToEndOfFile;
nsText := TNSString.Wrap(TNSString.Alloc.initWithData(data, NSUTF8StringEncoding));
list.text := nsText.cString;
showMessage(nsText.cString);
end;

Comments are closed.