From ab3ef87abf1928a3174f7d46af4f05ee712bbdaa Mon Sep 17 00:00:00 2001 From: Michael Peter Christen Date: Mon, 5 Dec 2022 17:30:11 +0100 Subject: [PATCH] fixed exec start command where a path contains spaces --- source/net/yacy/cora/util/Html2Image.java | 10 +++++++++- .../net/yacy/kelondro/logging/ThreadDump.java | 2 +- source/net/yacy/kelondro/util/OS.java | 20 +++++-------------- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/source/net/yacy/cora/util/Html2Image.java b/source/net/yacy/cora/util/Html2Image.java index 8e437a2fb..10bea0e2b 100644 --- a/source/net/yacy/cora/util/Html2Image.java +++ b/source/net/yacy/cora/util/Html2Image.java @@ -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 message = OS.execSynchronous(command); + List 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); diff --git a/source/net/yacy/kelondro/logging/ThreadDump.java b/source/net/yacy/kelondro/logging/ThreadDump.java index 6233e0b21..a4d842d02 100644 --- a/source/net/yacy/kelondro/logging/ThreadDump.java +++ b/source/net/yacy/kelondro/logging/ThreadDump.java @@ -137,7 +137,7 @@ public class ThreadDump extends HashMap> 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 diff --git a/source/net/yacy/kelondro/util/OS.java b/source/net/yacy/kelondro/util/OS.java index abf7d1695..7ca735e45 100644 --- a/source/net/yacy/kelondro/util/OS.java +++ b/source/net/yacy/kelondro/util/OS.java @@ -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 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 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 v = execSynchronous("/usr/local/bin/wkhtmltoimage"); + final List 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"); + } */ }