org.apache.tools.ant.taskdefs.Execute.setCommandline()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(8.6k)|赞(0)|评价(0)|浏览(173)

本文整理了Java中org.apache.tools.ant.taskdefs.Execute.setCommandline()方法的一些代码示例,展示了Execute.setCommandline()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Execute.setCommandline()方法的具体详情如下:
包路径:org.apache.tools.ant.taskdefs.Execute
类名称:Execute
方法名:setCommandline

Execute.setCommandline介绍

[英]Sets the commandline of the subprocess to launch.
[中]设置要启动的子流程的命令行。

代码示例

代码示例来源:origin: org.apache.ant/ant

/**
 * On VMS platform, we need to create a special java options file
 * containing the arguments and classpath for the java command.
 * The special file is supported by the "-V" switch on the VMS JVM.
 *
 * @param exe the Execute instance to alter.
 * @param command the command-line.
 */
public static void setupCommandLineForVMS(Execute exe, String[] command) {
  //Use the VM launcher instead of shell launcher on VMS
  exe.setVMLauncher(true);
  File vmsJavaOptionFile = null;
  try {
    String[] args = new String[command.length - 1];
    System.arraycopy(command, 1, args, 0, command.length - 1);
    vmsJavaOptionFile = JavaEnvUtils.createVmsJavaOptionFile(args);
    //we mark the file to be deleted on exit.
    //the alternative would be to cache the filename and delete
    //after execution finished, which is much better for long-lived runtimes
    //though spawning complicates things...
    vmsJavaOptionFile.deleteOnExit();
    String[] vmsCmd = {command[0], "-V", vmsJavaOptionFile.getPath()};
    exe.setCommandline(vmsCmd);
  } catch (IOException e) {
    throw new BuildException("Failed to create a temporary file for \"-V\" switch");
  }
}

代码示例来源:origin: org.apache.ant/ant

/**
 * Set the command line for the exe.
 * On VMS, hands off to {@link #setupCommandLineForVMS(Execute, String[])}.
 * @param exe executable.
 * @param command command to execute.
 */
private void setupCommandLine(Execute exe, String[] command) {
  //On VMS platform, we need to create a special java options file
  //containing the arguments and classpath for the java command.
  //The special file is supported by the "-V" switch on the VMS JVM.
  if (Os.isFamily("openvms")) {
    setupCommandLineForVMS(exe, command);
  } else {
    exe.setCommandline(command);
  }
}

代码示例来源:origin: kaaproject/kaa

private static void executeCommand(File workingDir, String... command) throws IOException {
 Execute exec = new Execute();
 if (workingDir == null) {
  String homeDir = System.getProperty("user.home");
  if (homeDir != null) {
   workingDir = new File(homeDir);
  }
 }
 if (workingDir != null) {
  exec.setWorkingDirectory(workingDir);
 }
 exec.setCommandline(command);
 exec.execute();
 if (exec.isFailure()) {
  throw new RuntimeException("Process returned bad exit value: " + exec.getExitValue());
 }
}

代码示例来源:origin: org.apache.ant/ant

/**
 * Run the command using the given Execute instance. This may be
 * overridden by subclasses.
 *
 * @param exe instance of Execute to run.
 *
 * @throws BuildException if the new process could not be started
 * only if failIfExecFails is set to true (the default).
 */
protected void runExec(Execute exe) throws BuildException {
  // show the command
  log(cmdl.describeCommand(), Project.MSG_VERBOSE);
  exe.setCommandline(cmdl.getCommandline());
  try {
    runExecute(exe);
  } catch (IOException e) {
    if (failIfExecFails) {
      throw new BuildException("Execute failed: " + e.toString(), e,
                   getLocation());
    }
    log("Execute failed: " + e.toString(), Project.MSG_ERR);
  } finally {
    // close the output file if required
    logFlush();
  }
}

代码示例来源:origin: org.apache.ant/ant

/**
 * Run the command.
 * @param cmd the command line to use.
 * @param out the output stream handler to use.
 * @return the exit code of the command.
 */
protected int runCmd(Commandline cmd, ExecuteStreamHandler out) {
  try {
    Project aProj = getProject();
    Execute exe = new Execute(out);
    exe.setAntRun(aProj);
    exe.setWorkingDirectory(aProj.getBaseDir());
    exe.setCommandline(cmd.getCommandline());
    return exe.execute();
  } catch (IOException e) {
    String msg = "Failed executing: " + cmd.toString()
      + ". Exception: " + e.getMessage();
    throw new BuildException(msg, getLocation());
  }
}

代码示例来源:origin: org.apache.ant/ant

/**
 * Run the command.
 * @param cmd the command line
 * @param handler an execute stream handler
 * @return the exit status of the command
 */
protected int run(Commandline cmd, ExecuteStreamHandler handler) {
  try {
    Execute exe = new Execute(handler);
    exe.setAntRun(getProject());
    exe.setWorkingDirectory(getProject().getBaseDir());
    exe.setCommandline(cmd.getCommandline());
    return exe.execute();
  } catch (IOException e) {
    throw new BuildException(e, getLocation());
  }
}

代码示例来源:origin: org.testng/testng

Execute execute= new Execute(new TestNGLogSH(this, Project.MSG_INFO, Project.MSG_WARN, (m_verbose == null || m_verbose < 5)),
               watchdog);
execute.setCommandline(cmd.getCommandline());
execute.setAntRun(getProject());
if(m_workingDir != null) {

代码示例来源:origin: apache/groovy

private void runForked(String[] commandLine) {
  final Execute executor = new Execute();
  executor.setAntRun(getProject());
  executor.setWorkingDirectory(getProject().getBaseDir());
  executor.setCommandline(commandLine);
  try {
    executor.execute();
  } catch (final IOException ioe) {
    throw new BuildException("Error running forked groovyc.", ioe);
  }
  final int returnCode = executor.getExitValue();
  if (returnCode != 0) {
    taskSuccess = false;
    if (errorProperty != null) {
      getProject().setNewProperty(errorProperty, "true");
    }
    if (failOnError) {
      throw new BuildException("Forked groovyc returned error code: " + returnCode);
    } else {
      log.error("Forked groovyc returned error code: " + returnCode);
    }
  }
}

代码示例来源:origin: org.apache.ant/ant

/**
 * Execute the given command are return success or failure
 * @param cmd command line to execute
 * @return the exit status of the subprocess or <code>INVALID</code>
 */
protected int run(Commandline cmd) {
  try {
    Project aProj = getProject();
    Execute exe = new Execute(
      new LogStreamHandler(this, Project.MSG_INFO, Project.MSG_WARN));
    exe.setAntRun(aProj);
    exe.setWorkingDirectory(aProj.getBaseDir());
    exe.setCommandline(cmd.getCommandline());
    return exe.execute();
  } catch (IOException e) {
    throw new BuildException(e, getLocation());
  }
}

代码示例来源:origin: org.apache.ant/ant

/**
 * A utility method that runs an external command. Writes the output and
 * error streams of the command to the project log.
 *
 * @param task The task that the command is part of. Used for logging
 * @param cmdline The command to execute.
 * @throws BuildException if the command does not exit successfully.
 */
public static void runCommand(Task task, String... cmdline)
  throws BuildException {
  try {
    task.log(Commandline.describeCommand(cmdline),
         Project.MSG_VERBOSE);
    Execute exe = new Execute(
      new LogStreamHandler(task, Project.MSG_INFO, Project.MSG_ERR));
    exe.setAntRun(task.getProject());
    exe.setCommandline(cmdline);
    int retval = exe.execute();
    if (isFailure(retval)) {
      throw new BuildException(cmdline[0]
        + " failed with return code " + retval, task.getLocation());
    }
  } catch (IOException exc) {
    throw new BuildException("Could not launch " + cmdline[0] + ": "
      + exc, task.getLocation());
  }
}

代码示例来源:origin: org.apache.ant/ant

/**
   * Get the execute object.
   * @param toExecute the command line to use.
   * @param streamhandler the stream handler to use.
   * @return the execute object.
   * @since Ant 1.6.3
   */
  protected Execute getExecute(Commandline toExecute,
                 ExecuteStreamHandler streamhandler) {
    Execute exe = new Execute(streamhandler, null);

    exe.setAntRun(getProject());
    if (topDir == null) {
      topDir = getProject().getBaseDir();
    }
    exe.setWorkingDirectory(topDir);

    exe.setCommandline(toExecute.getCommandline());
    return exe;
  }
}

代码示例来源:origin: org.apache.ant/ant

Project.MSG_WARN),
             null);
exe.setCommandline(toExecute.getCommandline());

代码示例来源:origin: org.apache.ant/ant

/**
 * Execute the created command line.
 *
 * @param  cmd            The command line to run.
 * @return                int the exit code.
 * @throws BuildException if something goes wrong
 */
protected int run(Commandline cmd) {
  try {
    Execute exe = new Execute(new LogStreamHandler(this,
        Project.MSG_INFO,
        Project.MSG_WARN));
    exe.setAntRun(getProject());
    exe.setWorkingDirectory(getProject().getBaseDir());
    exe.setCommandline(cmd.getCommandline());
    exe.setVMLauncher(false);  // Use the OS VM launcher so we get environment variables
    return exe.execute();
  } catch (java.io.IOException e) {
    throw new BuildException(e, getLocation());
  }
}

代码示例来源:origin: cbeust/testng

this, Project.MSG_INFO, Project.MSG_WARN, (m_verbose == null || m_verbose < 5)),
    watchdog);
execute.setCommandline(cmd.getCommandline());
execute.setAntRun(getProject());
if (m_workingDir != null) {

代码示例来源:origin: org.apache.ant/ant

.getPath());
try {
  execute.setCommandline(cloned.getCommandline());
  runExecute(execute);
} catch (IOException e) {

代码示例来源:origin: org.apache.ant/ant

exe.setCommandline(cmd.getCommandline());

代码示例来源:origin: org.apache.ant/ant

exe.setAntRun(project);
exe.setWorkingDirectory(project.getBaseDir());
exe.setCommandline(args);
exe.execute();
return !exe.isFailure();

代码示例来源:origin: org.apache.ant/ant

log("Calling java2iiop", Project.MSG_VERBOSE);
log(commandline.describeCommand(), Project.MSG_DEBUG);
execTask.setCommandline(commandline.getCommandline());
int result = execTask.execute();
if (Execute.isFailure(result)) {

代码示例来源:origin: org.apache.ant/ant

exe.setAntRun(project);
exe.setWorkingDirectory(project.getBaseDir());
exe.setCommandline(args);
exe.execute();
return !exe.isFailure();

代码示例来源:origin: org.apache.ant/ant

setupCommandLineForVMS(exe, cmdl.getCommandline());
} else {
  exe.setCommandline(cmdl.getCommandline());

相关文章