- public String getCommand(final EncodingOptions encodingOptions) {
- return converter.getCommand(source, target, encodingOptions);
+ private String encodeApostrophes(final String input) {
+ final StringBuilder result = new StringBuilder();
+
+ for (final char c : input.toCharArray()) {
+ if (c == '\'') {
+ result.append("'\\''");
+ continue;
+ }
+ result.append(c);
+ }
+
+ return result.toString();
+ }
+
+ public void execute(final EncodingOptions encodingOptions) {
+ try {
+ String command = getCommand(encodingOptions);
+
+ if (doUseTerminal())
+ command = "xterm -e '" + encodeApostrophes(command) + "'";
+
+ System.out.println("Executing command: " + command);
+
+ final Runtime runtime = Runtime.getRuntime();
+ final Process process = runtime.exec(new String[]{"/bin/bash", "-c", command});
+
+ process.waitFor();
+
+ } catch (final Exception e) {
+ System.out.println(e.toString());
+ e.printStackTrace();
+ }
+
+ }
+
+ private String getCommand(final EncodingOptions encodingOptions) {
+ return converter.getCommand(source, target, encodingOptions, targetFormat);