本文整理了Java中org.apache.commons.exec.Executor.setWorkingDirectory()
方法的一些代码示例,展示了Executor.setWorkingDirectory()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Executor.setWorkingDirectory()
方法的具体详情如下:
包路径:org.apache.commons.exec.Executor
类名称:Executor
方法名:setWorkingDirectory
[英]Set the working directory of the created process. The working directory must exist when you start the process.
[中]设置所创建进程的工作目录。启动进程时,工作目录必须存在。
代码示例来源:origin: nidi3/graphviz-java
public void execute(CommandLine cmd, @Nullable File workingDirectory) throws InterruptedException, IOException {
LOG.info("executing command {}", cmd.toString());
final ExecuteWatchdog watchdog = new ExecuteWatchdog(60 * 1000);
final Executor executor = new org.apache.commons.exec.DefaultExecutor();
executor.setWatchdog(watchdog);
if (workingDirectory != null) {
executor.setWorkingDirectory(workingDirectory);
}
LOG.debug("workdir: {}", executor.getWorkingDirectory());
final DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
final ByteArrayOutputStream out = new ByteArrayOutputStream();
final ByteArrayOutputStream err = new ByteArrayOutputStream();
executor.setStreamHandler(new PumpStreamHandler(out, err));
executor.execute(cmd, resultHandler);
resultHandler.waitFor();
final int exitCode = resultHandler.getExitValue();
if (out.size() > 0) {
LOG.info(out.toString());
}
if (exitCode != 0) {
throw new IOException(err.size() == 0 ? "command '" + cmd + "' didn't succeed" : err.toString());
}
}
}
代码示例来源:origin: com.addc.mojo/addc-mojo
/**
* Get an Executor that will run in the given directory with a watchdog set
* for the timeout.
*
* @param workDir
* The working directory for the process
* @return An executor.
*/
protected Executor getExecutor(File workDir) {
Executor executor= new DefaultExecutor();
executor.setWorkingDirectory(workDir);
if (timeout > 0) {
ExecuteWatchdog watchdog= new ExecuteWatchdog(timeout);
executor.setWatchdog(watchdog);
}
return executor;
}
代码示例来源:origin: org.apache.sling/org.apache.sling.testing.tools
executor.setWorkingDirectory(workFolder);
代码示例来源:origin: org.apache.sling/org.apache.sling.testing.serversetup
executor.setWorkingDirectory(workFolder);
代码示例来源:origin: gov.nasa.jpl.imce/gov.nasa.jpl.magicdraw.projectUsageIntegrityChecker
executor.setExitValue(0);
executor.setWatchdog(watchdog);
executor.setWorkingDirectory(pugTemp);
executor.execute(cmdLine, resultHandler);
代码示例来源:origin: ga4gh/dockstore
if (workingDir != null) {
LOG.info("working directory is " + workingDir.toString());
executor.setWorkingDirectory(workingDir);
代码示例来源:origin: com.netflix.genie/genie-web
.addArgument("./");
this.executor.setWorkingDirectory(jobDir);
.addArgument(localArchiveFile.getCanonicalPath());
this.executor.setWorkingDirectory(jobDir);
log.debug("Delete command: {}", deleteCommand);
this.executor.execute(deleteCommand);
代码示例来源:origin: org.apache.stanbol/org.apache.stanbol.commons.testing.jarexec
final Executor e = new DefaultExecutor();
if (this.workingDirectory != null) {
e.setWorkingDirectory(this.workingDirectory);
代码示例来源:origin: apache/stanbol
final Executor e = new DefaultExecutor();
if (this.workingDirectory != null) {
e.setWorkingDirectory(this.workingDirectory);
代码示例来源:origin: com.hotels/shunting-yard-replicator
public void run(Context context) {
try (OutputStream out = outStream(context); OutputStream err = errStream(context)) {
CommandLine cli = CommandLine
.parse(String.format("%s/%s", getProcEnvironment().get(CIRCUS_TRAIN_HOME_ENV_VAR), CIRCUS_TRAIN_HOME_SCRIPT));
cli.addArgument("--config=" + context.getConfigLocation());
if (!StringUtils.isEmpty(context.getCircusTrainConfigLocation())) {
cli.addArgument("--config=" + context.getCircusTrainConfigLocation());
}
Executor executor = new DefaultExecutor();
executor.setWorkingDirectory(new File(context.getWorkspace()));
executor.setStreamHandler(new PumpStreamHandler(out, err));
log.debug("Executing {} with environment {}", cli, getProcEnvironment());
int returnValue = executor.execute(cli, getProcEnvironment());
log.debug("Command exited with value {} ", returnValue);
if (returnValue != 0) {
throw new CircusTrainException("Circus Train exited with error value " + returnValue);
}
} catch (Throwable e) {
log.error("Unable to execute Circus Train", e);
}
}
代码示例来源:origin: org.codehaus.mojo/exec-maven-plugin
exec.setWorkingDirectory( workingDirectory );
fillSuccessCodes( exec );
代码示例来源:origin: mojohaus/exec-maven-plugin
exec.setWorkingDirectory( workingDirectory );
fillSuccessCodes( exec );
代码示例来源:origin: net.jangaroo/jangaroo-maven-plugin
private static void internalExecute(CommandLine cmdLine, OutputStream outputStream, File workingDirectory) throws IOException {
Executor executor = getExecutor();
ExecuteWatchdog watchdog = getExecuteWatchdog();
executor.setWatchdog(watchdog);
if (workingDirectory != null) {
executor.setWorkingDirectory(workingDirectory);
}
// set allowed exit values (0 is actually the default)
executor.setExitValue(0);
PumpStreamHandler psh = new PumpStreamHandler(outputStream);
executor.setStreamHandler(psh);
executor.execute(cmdLine);
if (watchdog.killedProcess()) {
throw new ExecuteException(String.format("Watchdog killed Sencha Cmd process after %s ms.", MAX_EXECUTION_TIME), 0);
}
}
代码示例来源:origin: gov.nasa.jpl.imce/gov.nasa.jpl.magicdraw.projectUsageIntegrityChecker
executor.setExitValue(0);
executor.setWatchdog(watchdog);
executor.setWorkingDirectory(pugTemp);
executor.execute(cmdLine, resultHandler);
代码示例来源:origin: talios/clojure-maven-plugin
exec.setWorkingDirectory(getWorkingDirectory());
ShutdownHookProcessDestroyer destroyer = new ShutdownHookProcessDestroyer();
exec.setProcessDestroyer(destroyer);
代码示例来源:origin: danielflower/app-runner
private static Executor createExecutor(LineConsumer consoleLogHandler, CommandLine command, File projectRoot, ExecuteWatchdog watchDog) {
Executor executor = new DefaultExecutor();
executor.setWorkingDirectory(projectRoot);
executor.setWatchdog(watchDog);
executor.setStreamHandler(new PumpStreamHandler(new WriterOutputStream(new WriterToOutputBridge(consoleLogHandler))));
consoleLogHandler.consumeLine(fullPath(executor.getWorkingDirectory()) + "> " + String.join(" ", command.toStrings()) + LINE_SEPARATOR);
return executor;
}
代码示例来源:origin: org.bitbucket.bradleysmithllc.etlunit/core
executor.setWorkingDirectory(pd.getWorkingDirectory());
代码示例来源:origin: com.googlecode.etl-unit/etlunit-core
executor.setWorkingDirectory(pd.getWorkingDirectory());
代码示例来源:origin: org.znerd/znerd-util
@Override
public CommandRunResult runCommand(File workingDirectory, String command, String... arguments) {
long start = System.currentTimeMillis();
ExecuteWatchdog watchdog = createWatchdog();
CommonsExecProcOutputBuffer buffer = new CommonsExecProcOutputBuffer();
Executor executor = createExecutor(buffer, watchdog);
CommandLine commandLine = createCommandLine(command, arguments);
int exitCode;
IOException exception;
log(INFO, "Setting working directory to: " + quote(workingDirectory) + '.');
String argumentsString = ArrayUtils.printQuoted(arguments, ", ", " and ");
try {
if (workingDirectory != null) {
executor.setWorkingDirectory(workingDirectory); // TODO: Error handling
}
log(INFO, "Executing command " + quote(command) + " with argument(s) " + argumentsString + '.');
exitCode = executor.execute(commandLine);
exception = null;
} catch (IOException cause) {
exitCode = -1;
exception = cause;
}
return createResult(start, buffer, exitCode, exception);
}
内容来源于网络,如有侵权,请联系作者删除!