fixed exec start command where a path contains spaces

pull/554/head
Michael Peter Christen 2 years ago
parent 17eec667fb
commit ab3ef87abf

@ -370,7 +370,15 @@ public class Html2Image {
// i.e. convert -density 300 -trim yacy.pdf[0] -trim -resize 1024x -crop x1024+0+0 -quality 75% yacy-convert-300.jpg
// note: both -trim are necessary, otherwise it is trimmed only on one side. The [0] selects the first page of the pdf
final String command = convertCmd + " -alpha remove -density " + density + " -trim " + pdf.getAbsolutePath() + "[0] -trim -resize " + width + "x -crop x" + height + "+0+0 -quality " + quality + "% " + image.getAbsolutePath();
List<String> message = OS.execSynchronous(command);
List<String> message = OS.execSynchronous(new String[] {
convertCmd,
"-alpha", "remove", "-density", Integer.toString(density),
"-trim", pdf.getAbsolutePath() + "[0]", "-trim",
"-resize" + Integer.toString(width) + "x",
"-crop x" + Integer.toString(height) + "+0+0",
"-quality", Integer.toString(quality) + "%",
image.getAbsolutePath()
});
if (image.exists()) return true;
ConcurrentLog.warn("Html2Image", "failed to create image with command: " + command);
for (final String m: message) ConcurrentLog.warn("Html2Image", ">> " + m);

@ -137,7 +137,7 @@ public class ThreadDump extends HashMap<ThreadDump.StackTrace, List<String>> imp
final int pid = OS.getPID();
// call kill -3 (SIGQUIT) on the pid to request a core dump from the current process
if (pid >= 0) try {OS.execSynchronous("kill -3 " + pid);} catch (final IOException e) {}
if (pid >= 0) try {OS.execSynchronous(new String[]{"kill", "-3", Integer.toString(pid)});} catch (final IOException e) {}
}
// read the log from the dump

@ -118,7 +118,6 @@ public final class OS {
return s;
}
@SuppressWarnings("deprecation")
public static void deployScript(final File scriptFile, final String theScript) throws IOException {
FileUtils.copy(UTF8.getBytes(theScript), scriptFile);
if(!isWindows){ // set executable
@ -141,7 +140,6 @@ public final class OS {
return p >= 0 ? NumberTools.parseIntDecSubstring(pids, 0, p) : -1;
}
@SuppressWarnings("deprecation")
public static void execAsynchronous(final File scriptFile) throws IOException {
// runs a script as separate thread
String starterFileExtension = null;
@ -164,15 +162,6 @@ public final class OS {
FileUtils.deletedelete(starterFile);
}
@SuppressWarnings("deprecation")
public static List<String> execSynchronous(final String command) throws IOException {
// runs a unix/linux command and returns output as Vector of Strings
// this method blocks until the command is executed
final Process p = Runtime.getRuntime().exec(command);
return readStreams(p);
}
@SuppressWarnings("deprecation")
public static List<String> execSynchronous(final String[] command) throws IOException {
// runs a unix/linux command and returns output as Vector of Strings
// this method blocks until the command is executed
@ -212,14 +201,15 @@ public final class OS {
public static void main(final String[] args) {
try {
final List<String> v = execSynchronous("/usr/local/bin/wkhtmltoimage");
final List<String> v = execSynchronous(new String[]{"/usr/local/bin/wkhtmltoimage"});
for (final String r: v) java.lang.System.out.println(r);
} catch (final IOException e) {
e.printStackTrace();
}
/*
if (args[0].equals("-m")) {
java.lang.System.out.println("Maximum possible memory: " + Integer.toString(getWin32MaxHeap()) + "m");
}
if (args[0].equals("-m")) {
java.lang.System.out.println("Maximum possible memory: " + Integer.toString(getWin32MaxHeap()) + "m");
}
*/
}

Loading…
Cancel
Save