0

I am trying to run exiftool through R to get metadata from photos using the system() command. When I run this on a mac, it works fine, but from windows I am not linking up with the cmd.exe properly and getting the following error from this code:

    exif_datetime <- function(path) {

     exif_cmd <- 'exiftool.pl -T -r -DateTimeOriginal '  
     cmd <- paste(exif_cmd, "'", path, "'" ,sep='')
     exif_time <- system(cmd, intern = TRUE) 

    exif_time
}
   photo_time <- exif_datetime('C:/Users/photo.jpg')
   photo_time



   Error in system(cmd, intern = TRUE) : 
   'CreateProcess' failed to run 'C:\Windows\exiftool.pl -T -r -DateTimeOriginal 'C:/Users/photo.jpg''

When I run the exiftool command from cmd.exe in Windows, I get the proper result. My exiftool.pl is in the C:Windows folder on my computer. Is there something regarding the PATH that I am missing? Also, I remember something about windows needing a shell, but I have not figured out if that is what I need in my case nor how to create one properly.

LAD
  • 141
  • 1
  • 7
  • 1
    Folder holding your script should be in PATH. Where do you run the command from (by hand)? Have you tried running the figure with double quote instead of a single quote (probably not the reason). – Roman Luštrik Feb 15 '16 at 16:35
  • Answer the questions @RomanLuštrik gave. Those were pretty much my exact thoughts/questions as well. – Dason Feb 15 '16 at 17:01
  • It looks like you're running the perl version of exiftool, not the Windows executable. Do you have perl installed on your Windows machine? – StarGeek Feb 15 '16 at 18:13
  • Maybe I'm confused about PATH. The command is being run from R. Am I understanding your question right? – LAD Feb 15 '16 at 18:21
  • Yes, perl is installed, and it works as exiftool.pl when running "exiftool.pl -T -r -DateTimeOriginal "C:/file" from the cmd terminal. – LAD Feb 15 '16 at 18:22
  • Try running the `system` call first, then wrap it into a function. What about running `system('exiftool.pl -T -r -DateTimeOriginal "C:/Users/photo.jpg"')` (notice the single/double quotes)? – Roman Luštrik Feb 15 '16 at 20:03

1 Answers1

1

Thanks for all your suggestions. I found a solution that works for me, involving the shell() command. I thought that it had to be incorporated with the system() command somehow, but it appears that it will work on its own.

    exif_datetime <- function(path) {

    exif_call <- 'exiftool.pl'  
    exif_cmd<-' -r -T -DateTimeOriginal '

    exif_timestamp <- shell(paste(exif_call, exif_cmd, path), intern=T) 

    exif_timestamp
    }
  photo_time <- exif_datetime('C:/Users/photo.jpg')
  photo_time


  [1] "2016:02:14 11:50:29"
LAD
  • 141
  • 1
  • 7