當前位置: 首頁>>代碼示例>>Java>>正文


Java Executor.setWorkingDirectory方法代碼示例

本文整理匯總了Java中org.apache.commons.exec.Executor.setWorkingDirectory方法的典型用法代碼示例。如果您正苦於以下問題:Java Executor.setWorkingDirectory方法的具體用法?Java Executor.setWorkingDirectory怎麽用?Java Executor.setWorkingDirectory使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.exec.Executor的用法示例。


在下文中一共展示了Executor.setWorkingDirectory方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setupSudoCredentials

import org.apache.commons.exec.Executor; //導入方法依賴的package包/類
public static ExecResult setupSudoCredentials(String password) {
    ExecCommand execCommand = new ExecCommand("sudo");
    execCommand.addArgument("--validate", false);
    execCommand.addArgument("--stdin", false);
    Executor executor = new DefaultExecutor();
    executor.setWorkingDirectory(execCommand.getWorkingDirectory());
    executor.setExitValues(execCommand.getExitValues());
    ExecOutputStream execOutputStream = new ExecOutputStream();
    executor.setStreamHandler(new PumpStreamHandler(execOutputStream, execOutputStream, new ExecInputStream(password)));
    try {
        executor.execute(execCommand);
    } catch (IOException e) {
        return new ExecResult(execOutputStream.getOutput(), e);
    }
    return new ExecResult(execOutputStream.getOutput());
}
 
開發者ID:ctco,項目名稱:gradle-mobile-plugin,代碼行數:17,代碼來源:ExecUtil.java

示例2: execCommand

import org.apache.commons.exec.Executor; //導入方法依賴的package包/類
@Deprecated
public static ExecResult execCommand(CommandLine commandLine, File workDir, int[] exitValues, boolean routeToCapture, boolean routeToStdout) {
    Executor executor = new DefaultExecutor();
    if (workDir != null) {
        executor.setWorkingDirectory(workDir);
    }
    if (exitValues != null) {
        executor.setExitValues(exitValues);
    }
    ExecOutputStream execOutputStream = new ExecOutputStream(routeToCapture, routeToStdout);
    PumpStreamHandler streamHandler = new PumpStreamHandler(execOutputStream);
    executor.setStreamHandler(streamHandler);
    try {
        executor.execute(commandLine);
    } catch (IOException e) {
        return new ExecResult(false, execOutputStream.getOutput(), e);
    }
    return new ExecResult(true, execOutputStream.getOutput(), null);
}
 
開發者ID:ctco,項目名稱:gradle-mobile-plugin,代碼行數:20,代碼來源:ExecUtil.java

示例3: executeCommand

import org.apache.commons.exec.Executor; //導入方法依賴的package包/類
public static ExecResult executeCommand(ExecCommand execCommand, ExecOutputStream execOutputStream) {
    Executor executor = new DefaultExecutor();
    executor.setWorkingDirectory(execCommand.getWorkingDirectory());
    executor.setExitValues(execCommand.getExitValues());
    executor.setStreamHandler(new PumpStreamHandler(execOutputStream));
    try {
        executor.execute(execCommand);
    } catch (IOException e) {
        return new ExecResult(execOutputStream.getOutput(), e);
    }
    return new ExecResult(execOutputStream.getOutput());
}
 
開發者ID:ctco,項目名稱:gradle-mobile-plugin,代碼行數:13,代碼來源:ExecUtil.java

示例4: executeCommandWithPipe

import org.apache.commons.exec.Executor; //導入方法依賴的package包/類
public static ExecResult executeCommandWithPipe(ExecCommand execCommand, ExecOutputStream execOutputStream, String pipeValue) {
    Executor executor = new DefaultExecutor();
    executor.setWorkingDirectory(execCommand.getWorkingDirectory());
    executor.setExitValues(execCommand.getExitValues());
    executor.setStreamHandler(new PumpStreamHandler(execOutputStream, execOutputStream, new ExecInputStream(pipeValue)));
    try {
        executor.execute(execCommand);
    } catch (IOException e) {
        return new ExecResult(execOutputStream.getOutput(), e);
    }
    return new ExecResult(execOutputStream.getOutput());
}
 
開發者ID:ctco,項目名稱:gradle-mobile-plugin,代碼行數:13,代碼來源:ExecUtil.java

示例5: resetSudoCredentials

import org.apache.commons.exec.Executor; //導入方法依賴的package包/類
public static ExecResult resetSudoCredentials() {
    ExecCommand execCommand = new ExecCommand("sudo");
    execCommand.addArgument("--remove-timestamp", false);
    Executor executor = new DefaultExecutor();
    executor.setWorkingDirectory(execCommand.getWorkingDirectory());
    executor.setExitValues(execCommand.getExitValues());
    ExecOutputStream execOutputStream = new ExecOutputStream();
    executor.setStreamHandler(new PumpStreamHandler(execOutputStream));
    try {
        executor.execute(execCommand);
    } catch (IOException e) {
        return new ExecResult(execOutputStream.getOutput(), e);
    }
    return new ExecResult(execOutputStream.getOutput());
}
 
開發者ID:ctco,項目名稱:gradle-mobile-plugin,代碼行數:16,代碼來源:ExecUtil.java

示例6: executeGoal

import org.apache.commons.exec.Executor; //導入方法依賴的package包/類
@Override
protected final void executeGoal() throws MojoExecutionException {
    init();
    LOG.info("command={}", command);

    final CommandLine cmdLine = createCommandLine();
    final Executor executor = new DefaultExecutor();
    try {
        final ByteArrayOutputStream bos = new ByteArrayOutputStream();
        final PumpStreamHandler psh = new PumpStreamHandler(bos);
        executor.setStreamHandler(psh);
        executor.setWorkingDirectory(getEventStoreDir());
        final int result = executor.execute(cmdLine);
        if (result != 0) {
            throw new MojoExecutionException(
                    "Error stopping the event store: " + result);
        }
        final List<String> messages = asList(bos.toString());
        logDebug(messages);
        deletePid();
        LOG.info("Event store successfully stopped");

    } catch (final IOException ex) {
        throw new MojoExecutionException(
                "Error executing the command line: " + cmdLine, ex);
    }

}
 
開發者ID:fuinorg,項目名稱:event-store-maven-plugin,代碼行數:29,代碼來源:EventStoreStopMojo.java

示例7: init

import org.apache.commons.exec.Executor; //導入方法依賴的package包/類
public void init() throws KMRuntimeException, InvalidResourceDefinitionException, InjectException, IOException {
        ctx = new KMContextImpl();
        host = ctx.getHost();
        Executor exec = new DefaultExecutor();
        File vagrantDir = new File(VAGRANTDIR);
        if (!vagrantDir.exists()) {
            if (!vagrantDir.mkdirs()) {
                throw new IOException("Unable to create " + vagrantDir.getPath());
            }
        }
        File vagrantfile = new File(vagrantDir, "Vagrantfile");
        if (!vagrantfile.exists()) {
            FileUtils.toString(vagrantfile, "Vagrant::Config.run do |config|\n  config.vm.box = \"ubuntu-precise64\"\nend\n");
        }
        exec.setWorkingDirectory(vagrantDir);
        exec.setStreamHandler(new PumpStreamHandler(System.out));
        exec.execute(CommandLine.parse("vagrant up"));
        resourceManager = ctx.getResourceManager();
//        resourceManager.registerJavaResource(TestResource.class, TEST);
//        resourceManager.registerJavaResource(UniqueTestResource.class, UNIQUETEST);
        Resource vagrant = resourceManager.createResource("vagrant:vagrant");
        vagrant.set("dir", VAGRANTDIR);
        vagrant.set("box", "ubuntu-precise64");
        SharedFolder testFolder = new SharedFolder(true, true, "test", TESTDIR, "/test");
        Resource testDirRes = resourceManager.createResource(testFolder);
        ctx.setDefaultParent(vagrant);
        sshHost = VagrantResource.initHost(sshHost, new LocalHost(), VAGRANTDIR);
        ctx.inject(sshHost);
//        try {
//            Field field = AbstractHost.class.getDeclaredField("hostProviderManager");
//            field.setAccessible(true);
//            field.set(sshHost, ctx.getProvidersManagementService().getProviderManager(HostProviderManager.class));
//        } catch (NoSuchFieldException | IllegalAccessException e) {
//            throw new STRuntimeException(e.getMessage(), e);
//        }
        sshHost.start();
    }
 
開發者ID:Kloudtek,項目名稱:kloudmake,代碼行數:38,代碼來源:AbstractVagrantTest.java


注:本文中的org.apache.commons.exec.Executor.setWorkingDirectory方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。