|
@@ -22,6 +22,7 @@ import java.io.InputStreamReader;
|
|
|
public class ElectronUtils {
|
|
|
private static final Logger log = LoggerFactory.getLogger(ElectronUtils.class);
|
|
|
private static final String WIN_PREFIX = "cmd /c ";
|
|
|
+ private static final String LINUX_PREFIX = "./";
|
|
|
|
|
|
/**
|
|
|
* 将URL响应内容转为PDF文件
|
|
@@ -38,22 +39,29 @@ public class ElectronUtils {
|
|
|
path = path.replaceFirst("/", "");
|
|
|
}
|
|
|
|
|
|
- String cmd = WIN_PREFIX + String.format(script, url, path);
|
|
|
+ String[] cmd = new String[]{WIN_PREFIX + String.format(script, url, path)};
|
|
|
return executeCommand(cmd, "GBK");
|
|
|
} else {
|
|
|
- String cmd = String.format(script, url, path);
|
|
|
- return executeCommand(cmd, "UTF-8");
|
|
|
+ String cmd = LINUX_PREFIX + String.format(script, url, path);
|
|
|
+ String[] commands = new String[]{
|
|
|
+ "/bin/bash",
|
|
|
+ "-c",
|
|
|
+ "export DISPLAY=':99.0'",
|
|
|
+ "Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &",
|
|
|
+ "cd /usr/local/nodejs/node_global/bin", cmd
|
|
|
+ };
|
|
|
+ return executeCommand(commands, "UTF-8");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 执行命令
|
|
|
*/
|
|
|
- private static boolean executeCommand(String cmd, String charsetName) {
|
|
|
+ private static boolean executeCommand(String[] commands, String charsetName) {
|
|
|
Process process;
|
|
|
|
|
|
try {
|
|
|
- process = Runtime.getRuntime().exec(cmd);
|
|
|
+ process = Runtime.getRuntime().exec(commands);
|
|
|
} catch (IOException e) {
|
|
|
log.error(e.getMessage());
|
|
|
return false;
|