RunProgram, command line and MacOS

Mac OSX specific forum
Seymour Clufley
Addict
Addict
Posts: 1233
Joined: Wed Feb 28, 2007 9:13 am
Location: London

RunProgram, command line and MacOS

Post by Seymour Clufley »

I'm in an awkward situation where I'm having to code an app for Windows and Mac, but I have never programmed for Mac in my life, and I don't even have a Mac computer to do development work on. I will have access to a friend's Mac in order to compile the app - but only once a day.

Luckily, 95% of my code uses PB's internal commands. The only problems I can foresee come from using external utilities - Curl, FFMPEG and SoX.

I've learned that MacOS has Curl built in. Can anyone tell me what would be the equivalent of this Windows code?

Code: Select all

*Buffer = AllocateMemory(SizeOf(Double))
prog.i = RunProgram("H:\curl.exe",param,WorkingDirectory,#PB_Program_Open|#PB_Program_Read)
While ProgramRunning(prog)
  If AvailableProgramOutput(prog)
    NumOfBytes = ReadProgramData(prog, *Buffer, SizeOf(*Buffer))
    OutputString$ + PeekS(*Buffer, NumOfBytes, #PB_UTF8)
  EndIf
  Delay(50)
Wend
CloseProgram(prog)
The other two utilities (FFMPEG and SoX) are more complicated, because they are not built into MacOS. Would they have to be installed on the user's system by an installation process, or could they simply be included with the app as standalone utilities, like on Windows?

I realise these are all "newbie" questions, but I'm guessing that asking them here is the fastest way to get the answers. I'll be grateful for any help.
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."
jamirokwai
Enthusiast
Enthusiast
Posts: 771
Joined: Tue May 20, 2008 2:12 am
Location: Cologne, Germany
Contact:

Re: RunProgram, command line and MacOS

Post by jamirokwai »

The other two utilities (FFMPEG and SoX) are more complicated, because they are not built into MacOS. Would they have to be installed on the user's system by an installation process, or could they simply be included with the app as standalone utilities, like on Windows?
I use the official ffmpeg-binary for macOS in 64 bits flavor from https://evermeet.cx/ffmpeg/, because they have one binary with all libraries embedded. Just put the ffmpeg to /full/path/to/. This is how I call it in my code to convert Full-HD MP4 to lower res MP4.

Code: Select all

File$ = "file.mp4"
Order$ = "-y -vf scale=1280x720 -c:v libx264 -preset slow -profile:v high -crf 18 -coder 1 -bf 2 -c:a aac -b:a 256k -profile:a aac_low"
Output$ = "file_out.mp4"

FFMPEG = RunProgram("/full/path/to/ffmpeg", " -i " + Chr(34) + File$ + Chr(34) + " " + Order$ + " " + Chr(34) + Output$ + Chr(34), "", #PB_Program_Open | #PB_Program_Read)

If FFMPEG
	While ProgramRunning(FFMPEG)
		Delay(15)
	Wend
	result = ProgramExitCode(FFMPEG)
	CloseProgram(FFMPEG)
EndIf
You can even put it in the .App, and ship it with your binary. But add some information about the license in your program.
Regards,
JamiroKwai
Seymour Clufley
Addict
Addict
Posts: 1233
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Re: RunProgram, command line and MacOS

Post by Seymour Clufley »

Thanks, Jamirokwai. Does the ffmpeg executable not have a file extension on MacOS? I downloaded the Mac zip and noticed that a lot of the files don't have extensions.
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."
jamirokwai
Enthusiast
Enthusiast
Posts: 771
Joined: Tue May 20, 2008 2:12 am
Location: Cologne, Germany
Contact:

Re: RunProgram, command line and MacOS

Post by jamirokwai »

Seymour Clufley wrote:Thanks, Jamirokwai. Does the ffmpeg executable not have a file extension on MacOS? I downloaded the Mac zip and noticed that a lot of the files don't have extensions.
No, they do not need an extension. As macOS is a unix*, files are marked as executables. Have a you look into an .app using Finder -> Right Click -> Show Package Content - I suspect the name, my OS is in German.
Regards,
JamiroKwai
User avatar
deseven
Enthusiast
Enthusiast
Posts: 362
Joined: Wed Jan 12, 2011 3:48 pm
Location: Serbia
Contact:

Re: RunProgram, command line and MacOS

Post by deseven »

Two things you may find useful:
1. libcurl bindings are integrated to PB, you can just use http library instead of calling system curl binary.
2. To find out the path to system utilities, you can simply open the terminal and use 'which' for that, for example 'which curl' will give you '/usr/bin/curl'.
Post Reply