ExifTool Forum

ExifTool => Developers => Topic started by: KalTrek on December 19, 2024, 09:12:02 AM

Title: ExifTool in Powershell script gives error with many files
Post by: KalTrek on December 19, 2024, 09:12:02 AM
Hi,
first of all thank you for this incredible tool.

I wrote a Powershell script to organize my pictures.
It just moves files from a folder to subfolder with name yyyy-mm-dd.
The script also moves "companion" files linked to the main image, i.e. xmp or acr, even when they have a different date.
I ran the script in a trial folder but now that I'm trying to use it in a "real" folder with over 3000 pictures, I get this error:

Error getting EXIF data with ExifTool: Program 'exiftool.exe' failed to run: StandardOutputEncoding is only supported when standard output is redirected.At D:\Pictures\!NEW PICS\2016-11 Giappone\move_files 1.25.ps1:207 char:25
+             $exifJson = & $global:ExifToolPath @args

Any help would be really appreciated.
Thank you.

Title: Re: ExifTool in Powershell script gives error with many files
Post by: Phil Harvey on December 19, 2024, 09:13:55 AM
PowerShell has lots of problems, especially with corrupting piped output.  I suggest rewriting your script to use some other shell or language.

Alternatively, I suggest posting this question on a PowerShell board.  Experienced people here will probably just tell you not to use PowerShell.

- Phil
Title: Re: ExifTool in Powershell script gives error with many files
Post by: KalTrek on December 19, 2024, 11:23:42 AM
Hi Phil,
thank you for the quick reply.

The problem is here:

 # Call ExifTool once for all files
            $exifJson = & $global:ExifToolPath @args

I thought that maybe someone could tell me an easy fix that eludes me.

Title: Re: ExifTool in Powershell script gives error with many files
Post by: StarGeek on December 19, 2024, 11:36:11 AM
That would take someone with understanding of PowerShell scripts.

The corruption that Phil refers to has to do with the fact that PS converts everything to UTF-16 (https://brianreiter.org/2010/01/29/powershells-object-pipeline-corrupts-piped-binary-data). You might try making sure that UTF-8 is being used.

But this is a PowerShell problem, not an exiftool one.

(Re-reading that article, I saw that it's even worse than simply converting everything to UTF-16. It's adding a carriage return 0x0d in front of every line feed 0x0a)