pharo

How to use commandline tools from within pharo


I tried reading UFFI book but my basic knowledge isn't good enough.

So could someone please explain me how I can call an existing commandline tool from within pharo?

Lets say I'm building a little tool to select folders including files. I want to group the data so that it fits into DVDs and add checksums and parity. Then I want to burn a set of DVD from within pharo with the data.

So the stuff I would like to call on my mac is:

  1. shasum
  2. diskutils list
  3. hdiutil burn

But how do I do it?

I tried something like:

shasum: filePath to: checksumFile
    ^ self ffiCall: #( int shasum(char * filepPath pathString, char * checksumFile) ) 
           library: 'libcrypto.dylib'

    

Or should I go for LibC like described here: https://fuhrmanator.github.io/2019/03/16/LibC-Pharo-experiments.html


Solution

  • UFFI is about to interacting with external libs directly from Pharo. On the other end, if you want to interact with cmd line commands (as separate processes) and tools, LibC is quite enough for most cases. Beware that calling LibC methods is blocking (process needs to wait for result of cmd line process). If you need more advanced stuff, seeing exit code, stdout and stdrr redirection, you can also use OSSubProcess library that gives you option also for Windows OS. See: https://github.com/pharo-contributions/OSSubprocess