Jump to content
softtouch

Execute external program/command and capture output

Recommended Posts

I need to execute external programs like youtube-dl, ffmpeg etc. and also execute chmod and such on macOS. I kept searching for days and days and did not find any working example.

Is there anything similar TDosCommand, but for firemonkey?

Share this post


Link to post

Delphi has always been inexplicably poor for calling external command line programs; FreePascal is actually much better at it (as is most everything else).

 

This is the standard code every Delphi user seems to use to do what you want (because only @Remy Lebeau and @David Heffernan understand it):

 

https://stackoverflow.com/questions/9119999/getting-output-from-a-shell-dos-app-into-a-delphi-app

 

 

 

  • Haha 1

Share this post


Link to post
35 minutes ago, Joseph MItzen said:

Delphi has always been inexplicably poor for calling external command line programs; FreePascal is actually much better at it (as is most everything else).

 

This is the standard code every Delphi user seems to use to do what you want (because only @Remy Lebeau and @David Heffernan understand it):

 

https://stackoverflow.com/questions/9119999/getting-output-from-a-shell-dos-app-into-a-delphi-app

 

 

 

Thanks, but thats unfortunately for Windows only, I need something like that for macOS/Firemonkey and just cant find anything that actually works properly.

Share this post


Link to post

for MACOS

I use

procedure TForm1.Exec(FileName: PWideChar);
var
  Workspace: NSWorkspace;
  NSApp: NSApplication;
  Nw: NSWindow;
begin

  if fileexists(FileName) then
  begin

    Workspace := TNSWorkspace.Create;

    Workspace.launchApplication(NSSTR(FileName));
    Workspace.release;
  end;

end;

 

and in the uses:

Macapi.Foundation, Macapi.ObjectiveC, Macapi.Helpers, Macapi.AppKit

 

to execute another program

 

or

use

_system(PAnsiChar(p_cmd));

to execute a command (e.g terminal command)

where p_cmd is string e,g '/usr/local/bin/curl "mycommandhere"

Edited by mewindy

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×