Passing arguments with spaces in MacOS

Started by JohnF, April 09, 2024, 06:54:57 PM

Previous topic - Next topic

JohnF

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


StarGeek

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, which says you have to use #DQUOTE$ for quotes.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

JohnF

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.

StarGeek

Have you checked the links on the main page, though some may be outdated.

A quick search here pulled up this old post that is specifically Pure Basic.  It uses the -stay_open option which means it doesn't run exiftool once per file which is Common Mistake #3.

For Python, from the link on the main page, you can find PyExiftool, which also uses the -Stay_Open option.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

JohnF

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