ExifTool Forum

ExifTool => Developers => Topic started by: JohnF on April 09, 2024, 06:54:57 PM

Title: Passing arguments with spaces in MacOS
Post by: JohnF on April 09, 2024, 06:54:57 PM
I've just finished my second utility using exiftool where I use PureBasic (a nice IDE with compiler) to create a simple UI and a small amount of code to call exiftool.  My programs work fine in Windows, but I have problems when passing arguments with blank spaces in MacOS.  Here's a dumbed down example.

Commandline$ = " -LensMake=Leica Filename.DNG"
Result = RunProgram("/usr/local/bin/exiftool",Commandline$,"")
Works fine.

When I set Commandline$  = " -LensMake=Leica AG"   then all that is written is Leica and the " AG" is lost.

When I try Commandline$ = " -LensMake='Leica AG'" then what gets written is 'Leica   meaning the single quote is just treated as text and has no significance.

I get the same result if I programmatically try to construct the Commandline$ like this - using double quotes - Chr(34) or single quotes Char(39)
Commandline$ = " -LensMake=" + Chr(39) + "Leica AG" + Chr(39)

On the other hand,  if I type the same command directly into a terminal window
/usr/local/bin/exiftool -LensMake='Leica AG' Filename.DNG works just as it should and correctly passes the full Leica AG.

Would you be able to suggest what syntax to I need to add so that I can pass string information with blank spaces in MacOS?

Thanks a million if you can help with this.

Best,
John

Title: Re: Passing arguments with spaces in MacOS
Post by: StarGeek on April 09, 2024, 07:24:42 PM
This would be a Pure Basic question, not an exiftool question.

A quick search on "Pure Basic RunProgram Parameter with space" comes up with pages like this one (https://www.purebasic.fr/english/viewtopic.php?p=305236#p305236), which says you have to use #DQUOTE$ for quotes.
Title: Re: Passing arguments with spaces in MacOS
Post by: JohnF on April 12, 2024, 01:58:46 AM
Hello StarGeek,

Thanks for your prodding to closer examine dependencies in PureBasic. It's great that this is and active and well supported forum. I posted in the PureBasic forum as well and got the answer I needed. 

I think it would be great if somewhere on the Exiftool website there was a section with examples on how to programmatically call Exiftool in both Windows and MacOS environments and using Python, PureBasic, and/or other environments that well suited for creating wrapper programs.

One of the forum experts posted this code.

Procedure simpleShell(ShellCommand$)
  Protected shell
  shell = RunProgram("/bin/zsh","","", #PB_Program_Open|#PB_Program_Write)
  If shell
      WriteProgramStringN(shell,ShellCommand$)
      WriteProgramData(shell,#PB_Program_Eof,0)
      While ProgramRunning(shell) : Delay(10) : Wend ; Wait until program quits
      CloseProgram(shell)
  EndIf
EndProcedure

simpleShell("/usr/local/bin/exiftool -LensMake=Voigtlander -LensModel='Color Skopar' -preserve -overwrite_original_in_place -X -m /Users/Elizabeth/Desktop/John/Temp")


My reply back to him... Yes, the code you provided solved the problem. From this I now understand what I was missing. I believed that sending the Commandline$ directly to exiftool within RunProgram (which works in windows) should work the same way in MacOS. It simply does not. I also believed that sending the Commandline$ would be equivalent to sending the string through WriteProgramStringN. This also seems not to be true. Finally, I now understand that sending the full command string to "/bin/zsh" is the same as executing it in the Terminal - which was exactly what you where trying to get across.

It would be great if there was some solid documentation for this - both for Windows as well as for MacOS. Maybe there is, but try as I might, I could not find it.
Title: Re: Passing arguments with spaces in MacOS
Post by: StarGeek on April 12, 2024, 02:50:32 AM
Have you checked the links on the main page (https://exiftool.org/#related_prog), though some may be outdated.

A quick search here pulled up this old post (https://exiftool.org/forum/index.php?topic=9851.0) that is specifically Pure Basic.  It uses the -stay_open option (https://exiftool.org/exiftool_pod.html#stay_open-FLAG) which means it doesn't run exiftool once per file which is Common Mistake #3 (https://exiftool.org/mistakes.html#M3).

For Python, from the link on the main page, you can find PyExiftool (https://github.com/sylikc/pyexiftool), which also uses the -Stay_Open option.
Title: Re: Passing arguments with spaces in MacOS
Post by: JohnF on April 14, 2024, 01:10:02 AM
Hi StarGeek,

Many thanks for your follow-up post.

It's clear that for all my previous searching, there are resources I missed.

Best,
John