Gimp invocation from Java

M

monochromec

I have the following problem when I try to invoke a shell script from a
running Java program. When using the script from the command line, all
works well. The script in question is a small batch file that simply
invokes GIMP to execute a pre-defined Scheme program that watermarks
and converts an image file.

When invoked from a JVM instance, GIMP itself starts, reads and reads
the script OK but then stops executing according to a process
monitoring utility.

Here's the Java snippet in question:

import java.io.*;
import java.util.*;
import java.lang.*;


public class Convert {
private static void convert (String [] files, String targetDir) {
int retV = 0;
for (int i = 0; i < files.length; i++) {
File file = new File (files );
String tmp = new String (file.getName ());
String base = new String (tmp.substring (0, tmp.lastIndexOf
(".")));
String f = new String (targetDir + "/" + base);
String fS = new String (f + "s");
f += ".jpg";
fS += ".jpg";
File ff = new File (f);
String pre = "";

if (! file.canRead () || file.lastModified () > ff.lastModified ())
{
final String [] args = {"bash.exe", "-c", "cv.sh " + files
+ " " + f + " " + fS};
try {
Process p = Runtime.getRuntime ().exec (args);
retV = p.waitFor ();
} catch (Exception e) {
System.out.println (e.toString ());
}
} else {
pre = ">";
}
System.out.println (pre + tmp + ":" + retV + "\n");
}
}
public static class FFileFilter implements FilenameFilter {
public boolean accept (File dir, String name) {
return name.toLowerCase ().endsWith (".bmp");
}
}
private static String [] getFiles (String dir) {
File f = new File (dir);

return f.list (new FFileFilter ());
}
public static void main(String[] args) {
String [] files = getFiles (args [0]);

convert (files, "img");
}
}

The shell script in question (cv.sh):


gimp-2.2 -c -i -d -b '(script-fu-process "'$1'" "'$2'" "'$3'")'

I've tried separating the cmd-line arguments for the cv.sh
invocation; the above format is the only version that works. The
environment is the following: Win XP SP2, gimp 2.2.7, Cygwin bash
2.05b.01, Sun jdk 1.5.0_02 as well as Eclipse 3.02 (I've tried both
Java environments to no avail).

Any thoughts?

Cheers, Christoph
 
G

Gordon Beaton

When invoked from a JVM instance, GIMP itself starts, reads and
reads the script OK but then stops executing according to a process
monitoring utility.

Followup set to c.l.j.help.

Please choose ONE relevant group to post your question to, not three
or more. And when you absolutely must post to multiple groups, don't
multipost. Crosspost instead.

The process is waiting for you to read from its output and error
streams, which you neglect to do in your code. Alternatively, redirect
the output of the child so it doesn't fill the output streams with
data that nobody is reading.
final String [] args =
{"bash.exe", "-c", "cv.sh " + files
+ " " + f + " " + fS};


Tip: you don't need to explicitly run a shell in order to run the
script, if the script starts with the correct #! line and is marked
executable. At least that's the case on Unix, I don't know about
Cygwin.

/gordon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top