Java exec exec(String command, String[] args_, String[] environment)

Here you can find the source of exec(String command, String[] args_, String[] environment)

Description

Executes the commands with args and environemnt in a separate process.

License

Apache License

Parameter

Parameter Description
command The command to ecxecute.
args_ The arguments.
environment The environment key-value pairs.

Return

The new process.

Declaration


public final static Process exec(String command, String[] args_, String[] environment)
        throws java.io.IOException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**//  w  w w .  ja  v a  2  s.  c  o m
      Executes the commands with args and environemnt in a separate process.
          
      @param command The command to ecxecute.
      @param args_   The arguments.
      @param environment The environment key-value pairs.
      @return The new process.
      */

    public final static Process exec(String command, String[] args_, String[] environment)
            throws java.io.IOException {
        // setup params
        String[] args = new String[1];
        if (args_ != null) {
            args = new String[args_.length + 1];
            for (int i = 0; i < args_.length; i++)
                args[i + 1] = args_[i];
        }

        // let's go...
        args[0] = command;

        // param debug
        /*
        for(int i = 0; i < args.length; i++)
        out.println("[" + i + "]" + args[i]);
            
        for(int i = 0; i < environment.length; i++)
        out.println("[" + i + "]" + environment[i]);
        */
        // end of param debug

        return Runtime.getRuntime().exec(args, environment);
    }
}

Related

  1. exec(String command)
  2. exec(String command)
  3. exec(String command)
  4. exec(String command)
  5. exec(String command, String workingDir)
  6. exec(String command[], boolean stop)
  7. exec(String exec)
  8. exec(String program, String... args)
  9. exec(String pwd, boolean quiet, String... command)