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
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