	public void run() {
		ProcessBuilder pb = new ProcessBuilder(cmdArray);
		try {
			LOGGER.debug("Starting " + cmdLine);
			if (params.outputFile != null && params.outputFile.getParentFile().isDirectory()) {
				pb.directory(params.outputFile.getParentFile());
			}
			if (params.workDir != null && params.workDir.isDirectory()) {
				pb.directory(params.workDir);
			}
			if (params.env != null && !params.env.isEmpty()) {
				Map<String,String> environment = pb.environment();
				String PATH = params.env.get("PATH") + File.pathSeparator + environment.get("PATH");
				environment.putAll(params.env);
				environment.put("PATH", PATH);
			}
			process = pb.start();
			PMS.get().currentProcesses.add(process);
			stderrConsumer = keepStderr
				? new OutputTextConsumer(process.getErrorStream(), true)
				: new OutputTextLogger(process.getErrorStream());
			stderrConsumer.start();
			outConsumer = null;
			if (params.outputFile != null) {
				LOGGER.debug("Writing in " + params.outputFile.getAbsolutePath());
				outConsumer = keepStdout
					? new OutputTextConsumer(process.getInputStream(), false)
					: new OutputTextLogger(process.getInputStream());
			} else if (params.input_pipes[0] != null) {
				LOGGER.debug("Reading pipe: " + params.input_pipes[0].getInputPipe());
				bo = params.input_pipes[0].getDirectBuffer();
				if (bo == null || params.losslessaudio || params.lossyaudio || params.no_videoencode) {
					InputStream is = params.input_pipes[0].getInputStream();
					outConsumer = new OutputBufferConsumer((params.avidemux) ? new AviDemuxerInputStream(is, params, attachedProcesses) : is, params);
					bo = outConsumer.getBuffer();
				}
				bo.attachThread(this);
				new OutputTextLogger(process.getInputStream()).start();
			} else if (params.log) {
				outConsumer = keepStdout
					? new OutputTextConsumer(process.getInputStream(), true)
					: new OutputTextLogger(process.getInputStream());
			} else {
				outConsumer = new OutputBufferConsumer(process.getInputStream(), params);
				bo = outConsumer.getBuffer();
				bo.attachThread(this);
			}
			if (params.stdin != null) {
				params.stdin.push(process.getOutputStream());
			}
			if (outConsumer != null) {
				outConsumer.start();
			}
			Integer pid = ProcessUtil.getProcessID(process);
			if (pid != null) {
				LOGGER.debug("Unix process ID (" + cmdArray[0] + "): " + pid);
			}
			ProcessUtil.waitFor(process);
			try {
				if (outConsumer != null) {
					outConsumer.join(1000);
				}
			} catch (InterruptedException e) {
			}
			if (bo != null) {
				bo.close();
			}
		} catch (Exception e) {
			LOGGER.error("Fatal error in process initialization: ", e);
			stopProcess();
		} finally {
			if (!destroyed && !params.noexitcheck) {
				try {
					success = true;
					if (process != null && process.exitValue() != 0) {
						LOGGER.info("Process " + cmdArray[0] + " has a return code of " + process.exitValue() + "! Maybe an error occurred... check the log file");
						success = false;
					}
				} catch (IllegalThreadStateException itse) {
					LOGGER.error("An error occurred", itse);
				}
			}
			if (attachedProcesses != null) {
				for (ProcessWrapper pw : attachedProcesses) {
					if (pw != null) {
						pw.stopProcess();
					}
				}
			}
			PMS.get().currentProcesses.remove(process);
		}
	}

	public void run() {
		ProcessBuilder pb = new ProcessBuilder(cmdArray);
		try {
			LOGGER.debug("Starting " + cmdLine);
			if (params.outputFile != null && params.outputFile.getParentFile().isDirectory()) {
				pb.directory(params.outputFile.getParentFile());
			}
			if (params.workDir != null && params.workDir.isDirectory()) {
				pb.directory(params.workDir);
			}
			if (params.env != null && !params.env.isEmpty()) {
				Map<String,String> environment = pb.environment();
				String sysPathKey = PMS.get().isWindows() ? "Path" : "PATH";
				String PATH = params.env.containsKey("PATH") ? params.env.get("PATH") :
					params.env.containsKey("path") ? params.env.get("path") :
					params.env.containsKey("Path") ? params.env.get("Path") : null;
				if (PATH != null) {
					PATH += (File.pathSeparator + environment.get(sysPathKey));
				}
				environment.putAll(params.env);
				if (PATH != null) {
					environment.put(sysPathKey, PATH);
				}
			}
			process = pb.start();
			PMS.get().currentProcesses.add(process);
			stderrConsumer = keepStderr
				? new OutputTextConsumer(process.getErrorStream(), true)
				: new OutputTextLogger(process.getErrorStream());
			stderrConsumer.start();
			outConsumer = null;
			if (params.outputFile != null) {
				LOGGER.debug("Writing in " + params.outputFile.getAbsolutePath());
				outConsumer = keepStdout
					? new OutputTextConsumer(process.getInputStream(), false)
					: new OutputTextLogger(process.getInputStream());
			} else if (params.input_pipes[0] != null) {
				LOGGER.debug("Reading pipe: " + params.input_pipes[0].getInputPipe());
				bo = params.input_pipes[0].getDirectBuffer();
				if (bo == null || params.losslessaudio || params.lossyaudio || params.no_videoencode) {
					InputStream is = params.input_pipes[0].getInputStream();
					outConsumer = new OutputBufferConsumer((params.avidemux) ? new AviDemuxerInputStream(is, params, attachedProcesses) : is, params);
					bo = outConsumer.getBuffer();
				}
				bo.attachThread(this);
				new OutputTextLogger(process.getInputStream()).start();
			} else if (params.log) {
				outConsumer = keepStdout
					? new OutputTextConsumer(process.getInputStream(), true)
					: new OutputTextLogger(process.getInputStream());
			} else {
				outConsumer = new OutputBufferConsumer(process.getInputStream(), params);
				bo = outConsumer.getBuffer();
				bo.attachThread(this);
			}
			if (params.stdin != null) {
				params.stdin.push(process.getOutputStream());
			}
			if (outConsumer != null) {
				outConsumer.start();
			}
			Integer pid = ProcessUtil.getProcessID(process);
			if (pid != null) {
				LOGGER.debug("Unix process ID (" + cmdArray[0] + "): " + pid);
			}
			ProcessUtil.waitFor(process);
			try {
				if (outConsumer != null) {
					outConsumer.join(1000);
				}
			} catch (InterruptedException e) {
			}
			if (bo != null) {
				bo.close();
			}
		} catch (Exception e) {
			LOGGER.error("Fatal error in process initialization: ", e);
			stopProcess();
		} finally {
			if (!destroyed && !params.noexitcheck) {
				try {
					success = true;
					if (process != null && process.exitValue() != 0) {
						LOGGER.info("Process " + cmdArray[0] + " has a return code of " + process.exitValue() + "! Maybe an error occurred... check the log file");
						success = false;
					}
				} catch (IllegalThreadStateException itse) {
					LOGGER.error("An error occurred", itse);
				}
			}
			if (attachedProcesses != null) {
				for (ProcessWrapper pw : attachedProcesses) {
					if (pw != null) {
						pw.stopProcess();
					}
				}
			}
			PMS.get().currentProcesses.remove(process);
		}
	}
