File not readable while running command in java

A plethora of command-line scripts that perform geometric transforms, blurs, sharpens, edging, noise removal, and color manipulations.
Post Reply
Sveind
Posts: 2
Joined: 2014-01-31T13:50:16-07:00
Authentication code: 6789

File not readable while running command in java

Post by Sveind » 2014-01-31T16:13:58-07:00

Hello,

I've been trying to run like a batch so I can clean various images using textcleaner and when I run them in the terminal it all goes fine but once I enter the same command into java

Code: Select all

String output = obj.executeCommand("/Users/myuser/Documents/textcleaner/textcleaner -g -e none -f 10 -o 5 original.jpg out.jpg");
I get the error:
--- FILE original.jpg NOT READABLE OR HAS ZERO SIZE ---
I know the file it's there and just to make sure I added a couple of extra lines to the textcleaner script to show me if the file is there but no matter what I do I get that error, I've added the complete path to the image from root, tried moving it around, added the script to my java folder, everything I can think of. Even harcoded the paths to the images into the script but nothing.

What am I missing? Why isn't it working?

Thank you for your time
Sveind

User avatar
fmw42
Posts: 25022
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: File not readable while running command in java

Post by fmw42 » 2014-01-31T19:16:01-07:00

Try these pointers (as on my ImageMagick scripts home page), especially the two about PATH and tmp directory. Perhaps java also needs some variable set to know where IM resides. I know nothing about running scripts from java. If you figure this out, please let us know for future reference.


Pointers for use:
Download the script
Change the name to add or remove the .sh as desired when running
Set the script to executable (chmod u+x)
Find the full path to where IM (convert) resides by typing in a shell terminal window: type -a convert
If type -a convert returns more than one path, type in a shell terminal window: path2/convert -version, where path2 is each of the paths found. Decide which version of IM you want to use.
Modify your PATH environment variable so that it includes the full path to where IM (convert) resides (often /usr/bin or /usr/local/bin). This can be done by editing your .profile file.
Alternately, edit the script somewhere between the comments and the first use of any IM command, such as just below the defaults section to add the following two lines:
imdir="path2" #(such as imdir="/usr/local/bin" or imdir="/usr/bin")
PATH="${imdir}:${PATH}"
Open a shell terminal window
bash /fullpathto/scriptname(.sh) arguments /fullpathto/inputimage /fullpathto/outputimage
To avoid the bash and just use scriptname(.sh) ... set your PATH to contain the location of the script
Optionally edit the script to change the default directory (found after the defaults section) from dir="." to dir="/tmp"

Sveind
Posts: 2
Joined: 2014-01-31T13:50:16-07:00
Authentication code: 6789

Re: File not readable while running command in java

Post by Sveind » 2014-02-05T10:12:58-07:00

Hi,

Well I figured it out thanks to the pointers below, the only thing I did was change the script extension to .sh and modify the script so when it uses the command 'convert' I give it the whole PATH so (in my case) /usr/local/bin/convert -foo...

Everything else remainds pretty much the same.

Thank you for your time.
Sveind

User avatar
fmw42
Posts: 25022
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: File not readable while running command in java

Post by fmw42 » 2014-02-05T11:28:01-07:00

Sveind wrote:Hi,

Well I figured it out thanks to the pointers below, the only thing I did was change the script extension to .sh and modify the script so when it uses the command 'convert' I give it the whole PATH so (in my case) /usr/local/bin/convert -foo...

Everything else remainds pretty much the same.

Thank you for your time.
Sveind

The edit for the full path could have been achieved in one place by following

edit the script somewhere between the comments and the first use of any IM command, such as just below the defaults section to add the following two lines:

imdir="path2" #(such as imdir="/usr/local/bin" or imdir="/usr/bin")
PATH="${imdir}:${PATH}"

Post Reply