Ejemplo n.º 1
0
 public void start(boolean restart) throws IOException {
   ProcessQuery processQuery = new ProcessQuery("soffice.bin", unoUrl.getAcceptString());
   long existingPid = processManager.findPid(processQuery);
   if (!(existingPid == PID_NOT_FOUND || existingPid == PID_UNKNOWN)) {
     throw new IllegalStateException(
         String.format(
             "a process with acceptString '%s' is already running; pid %d",
             unoUrl.getAcceptString(), existingPid));
   }
   if (!restart) {
     prepareInstanceProfileDir();
   }
   List<String> command = new ArrayList<String>();
   File executable = OfficeUtils.getOfficeExecutable(officeHome);
   if (runAsArgs != null) {
     command.addAll(Arrays.asList(runAsArgs));
   }
   command.add(executable.getAbsolutePath());
   command.add("-accept=" + unoUrl.getAcceptString() + ";urp;");
   command.add("-env:UserInstallation=" + OfficeUtils.toUrl(instanceProfileDir));
   command.add("-headless");
   command.add("-nocrashreport");
   command.add("-nodefault");
   command.add("-nofirststartwizard");
   command.add("-nolockcheck");
   command.add("-nologo");
   command.add("-norestore");
   ProcessBuilder processBuilder = new ProcessBuilder(command);
   if (PlatformUtils.isWindows()) {
     addBasisAndUrePaths(processBuilder);
   }
   logger.info(
       String.format(
           "starting process with acceptString '%s' and profileDir '%s'",
           unoUrl, instanceProfileDir));
   process = processBuilder.start();
   pid = processManager.findPid(processQuery);
   if (pid == PID_NOT_FOUND) {
     throw new IllegalStateException(
         String.format(
             "process with acceptString '%s' started but its pid could not be found",
             unoUrl.getAcceptString()));
   }
   logger.info("started process" + (pid != PID_UNKNOWN ? "; pid = " + pid : ""));
 }
Ejemplo n.º 2
0
 private File getInstanceProfileDir(File workDir, UnoUrl unoUrl) {
   String dirName =
       ".jodconverter_" + unoUrl.getAcceptString().replace(',', '_').replace('=', '-');
   return new File(workDir, dirName);
 }