I am trying to run shell scripts with Orfeo-toolbox commands, and I'm new to all this.... (I'm working in Windows 7).

I can type

otbcli_ComputeImagesStatistics -il Imagery/P1_10cm1.tif Imagery/P2_10c1.tif -out ImageAnalysis/Stats12_JUNK3.xml

directly into the OSGeo4W shell window and things work fine. Now I'd like to put more commands in a script and run them all at once.

I'm following the advice from this question.

If I save that text in a file called TryShell.sh and enter in shell window:

sh TryShell.sh

I get the error TryShell.sh: line 1: otbcli_ComputeImagesStatistics: command not found

Why does the otbcli command work in the shell but not in the shell script?

  • My guess is that the location of the command's executable is not known to the operating system. Try adding its folder to your path. In the OSGeo3W shell, it has that information, thus the command works. – mkennedy Dec 18 '14 at 22:44

Working in person with a friend, I think I figured it out. It turns out you can save the commands in a .bat file and just type that file into the prompt in the OSGeo4W shell. This works without setting any path.

** The catch, is that it seems that commands like otbcli_ComputeImagesStatistics are themselves batch calls, so if I put more than one of them in the same .bat file it would only execute the first one. The problem was solved by putting "call" on the line in front of the otbcli_* commands.

So to sum up, make a file TEST.bat, with commands like:

call otbcli_ComputeImagesStatistics -il QB_1_ortho.tif -out EstimateImageStatisticsQB1.xml
call otbcli_ComputeImagesStatistics -il QB_2_ortho.tif -out EstimateImageStatisticsQB3.xml
call otbcli_ComputeImagesStatistics -il QB_3_ortho.tif -out EstimateImageStatisticsQB3.xml

and then type Test.bat at the prompt in the OSGeo4W shell. This was tested on Windows 7 and 8.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.