0

Trying this from TextMate. Results shown at end. If I copy the result into Terminal it runs fine. Probably something simple. I shortened the paths with ... in this submission

#!/usr/bin/env ruby

require 'shellwords'

InputDirPath  = ".../OrthoTIF-3bands/"
OutputDirPath = ".../Ortho-compressed/"
i = 0
Dir.foreach(InputDirPath) do |item|
  next if item == '.' or item == '..'
  i += 1
  name = File.basename(item,"tif")
  puts "\n#{i}. gdal_translate -co COMPRESS=JPEG -co PHOTOMETRIC=YCBCR #{InputDirPath.shellescape}#{item.shellescape} #{OutputDirPath.shellescape}/#{name}_Compressed.tif"
  output =     `gdal_translate -co COMPRESS=JPEG -co PHOTOMETRIC=YCBCR #{InputDirPath.shellescape}#{item.shellescape} #{OutputDirPath.shellescape}/#{name}_Compressed.tif`
  puts output
end

--> 1. gdal_translate -co COMPRESS=JPEG -co PHOTOMETRIC=YCBCR .../OrthoTIF-3bands/Bradshaw_Mts.Ortho.tif .../Ortho-compressed//Bradshaw_Mts.Ortho._Compressed.tif
--> sh: gdal_translate: command not found
Greg
  • 2,359
  • 5
  • 22
  • 35
  • 1
    Could you run it with an extra: `puts \`which gdal_translate\`` - maybe it's not in your PATH? – stef Nov 28 '15 at 19:51
  • Please explain what the problem is. As is, you haven't asked a question, just showed some code and an output. What do you expect the code to do? Please read "[ask]" along with the links on that page to get an idea what we need. Also, in Ruby `InputDirPath` should be `INPUT_DIR_PATH` and `OutputDirPath` should be `OUTPUT_DIR_PATH`. We use SNAKE_CASE for constants. – the Tin Man Nov 28 '15 at 20:11
  • Thank you both. GDAL installed in a non-standard (to this relative beginner) path. /Library/Frameworks/GDAL.framework/Programs/gdal_translate. – Greg Dec 02 '15 at 18:13
  • Sorry I didn't ask any explicit question. Sloppy. But the question was implied as you two figured out. – Greg Dec 02 '15 at 18:21

1 Answers1

2
command not found

Very like the problem is your sub-shell's path. Instead of trying to rely on the OS's ability to search a path, you need to provide the explicit/absolute path to the command.

If gdal_translate is in /usr/local/bin, then use:

/usr/local/bin/gdal_translate 
the Tin Man
  • 158,662
  • 42
  • 215
  • 303