About Runtime.exec () usage

2010-09-06  来源:本站原创  分类:Java  人气:180 

public Process exec (String command)
throws IOException in a separate process in the specified string command.
This is a useful approach. The exec (command) form of call, its behavior and call exec (command, null, null) exactly the same.

Parameters:
command - a specified system command.
Return:
A new Process object for managing the process of throwing child:
SecurityException - if a security manager exists and its checkExec method does not allow to create a child process
IOException - In the event of I / O error
NullPointerException - if command is null
IllegalArgumentException - If command is empty

public Process exec (String command,
String [] envp)
throws IOException separate process in the specified environment string in the specified order.
This is a useful approach. The exec (command, envp) call the form, its behavior and call exec (command, envp, null) exactly the same.

Parameters:
command - a specified system command.
envp - array of strings, where each element of the environment variables set the format name = value; if the child process should inherit the current process environment, or the parameter is null.
Return:
A new Process object for managing the process of throwing child:
SecurityException - if a security manager exists and its checkExec method does not allow to create a child process
IOException - In the event of I / O error
NullPointerException - if command is null, or envp element of the null
IllegalArgumentException - If command is empty

public Process exec (String command,
String [] envp,
File dir)
throws IOException in a specified environment and working directory of the independence process in the specified string command.
This is a useful approach. The exec (command, envp, dir) form of call, its behavior and call exec (cmdarray, envp, dir) exactly the same, which is the command cmdarray array of all tags.

More precisely, you can use by calling the new StringTokenizer (command) command string to create the StringTokenizer to decompose the tag does not call for further changes in character class. And then tag generator tags generated in the same order into the new string array cmdarray in.

Parameters:
command - a specified system command.
envp - array of strings, where each element of the environment variables set the format name = value; if the child process should inherit the current process environment, or the parameter is null.
dir - the working directory of the child process; if the child process should inherit the working directory of the current process, then the parameter is null.
Return:
A new Process object for managing the process of throwing child:
SecurityException - if a security manager exists and its checkExec method does not allow to create a child process
IOException - In the event of I / O error
NullPointerException - if command is null, or some elements null envp
IllegalArgumentException - If command is empty

public Process exec (String [] cmdarray)
throws IOException in a separate process in the specified commands and variables.
This is a useful approach. The exec (cmdarray) form of call, its behavior and call exec (cmdarray, null, null) exactly the same.

Parameters:
cmdarray - including the call to an array of commands and their parameters.
Return:
A new Process object for managing the process of throwing child:
SecurityException - if a security manager exists and its checkExec method does not allow to create a child process
IOException - In the event of I / O error
NullPointerException - if cmdarray is null, or some elements null cmdarray
IndexOutOfBoundsException - if cmdarray is an empty array (length 0)

public Process exec (String [] cmdarray,
String [] envp)
throws IOException independence process in the specified environment to perform the specified commands and variables.
This is a useful approach. The exec (cmdarray, envp) call the form, its behavior and call exec (cmdarray, envp, null) exactly the same.

Parameters:
cmdarray - including the call to an array of commands and their parameters.
envp - array of strings, where each element of the environment variables set the format name = value; if the child process should inherit the current process environment, or the parameter is null.
Return:
A new Process object for managing the process of throwing child:
SecurityException - if a security manager exists and its checkExec method does not allow to create a child process
IOException - In the event of I / O error
NullPointerException - if cmdarray is null, or cmdarray of an element is null, or some elements null envp
IndexOutOfBoundsException - if cmdarray is an empty array (length 0)

public Process exec (String [] cmdarray,
String [] envp,
File dir)
throws IOException in the specified environment and working directory of the independence process in the implementation of the specified commands and variables.
The given string represents a command-line array cmdarray tag array of strings envp, said the "environment" variable settings, this method creates a new process, while the specified command on the implementation of this process.

This method checks whether cmdarray a valid operating system command. Effective depends on what the command system, but the order must have at least one non-null string of non-empty list.

If envp is null, then the child process will inherit the current process environment settings.

ProcessBuilder.start () is now the environment has been modified to enable a process of first choice.

dir specifies the new child process working directory. If dir is null, then the child process will inherit the current process of the current working directory.

If the security manager is present, with the first element of the array cmdarray as a variable to call the security manager checkExec method. This may lead to throw SecurityException.

Start the operating system the way the process depends entirely on the system. There are many aspects of which will result in an error:

Operating system program file was not found.
The program file access is denied.
Working directory does not exist.
All this would throw an exception. The exception of the specific characteristics depending on the system, but it is always a subclass of IOException.

Parameters:
cmdarray - including the call to an array of commands and their parameters.
envp - array of strings, where each element of the environment variables set the format name = value, if the child process should inherit the current process environment, or the parameter is null.
dir - the working directory of the child process; if the child process should inherit the working directory of the current process, then the parameter is null.
Return:
A new Process object for managing the process of throwing child:
SecurityException - if a security manager exists and its checkExec method does not allow to create a child process
IOException - In the event of I / O error
NullPointerException - if cmdarray is null, or cmdarray of an element is null, or whether some elements are null envp
IndexOutOfBoundsException - if cmdarray is an empty array (length 0)

相关文章
  • About Runtime.exec () usage 2010-09-06

    public Process exec (String command) throws IOException in a separate process in the specified string command. This is a useful approach. The exec (command) form of call, its behavior and call exec (command, null, null) exactly the same. Parameters:

  • Runtime.exec use good article (rpm) 2010-10-23

    First, the English original address http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html Second, it almost means the first English translation of class Runtime that point of it, he is a runtime environment with the JVM-related classes, th

  • Call Runtime.exec () the number of traps 2010-11-12

    Runtime package the java runtime environment. Through the Runtime instance, java applications to run with the environmental connection. Runtime in the jvm to maintain a single case, it is not through the Runtime class constructor. Only through Runtim

  • 执行Runtime.exec异常: error=12,Cannot allocate memory 2012-02-06

    Exception Trace: In the Linux circumstance, when the program executes till this place: Process p = Runtime.getRuntime().exec(cmdArr); it throws an exception like this: java.io.IOException: Cannot run program "/opt/X.sh": java.io.IOException: err

  • Runtime.exec permission issues 2010-09-17

    Many applications call Runtime.exec time or create a service authority is not enough when the situation will be encountered. Can use the following solutions: AndroidManifest.xml: <Manifest xmlns: android = "http://schemas.android.com/apk/res/andro

  • java使用Runtime.exec执行linux命令重定向或管道问题 2013-05-28

    Java具有使用Runtime.exec对本地程序调用进行重定向的能力,但是用重定向或者管道进行命令调用将会出错. 这个问题诸如这个童鞋一样:http://www.codeweblog.com/question/586186_112601 当命令中含有管道(即命令符 | )的时候,就会出问题,如下图 解决方式很简单,用sh -c ,再加上原先的命令串即可解决问题:

  • Java执行Runtime.exec(shell)报Cannot allocate memory 2014-06-05

    在Linux下用java的Runtime.getRuntime().exec(cmd)方式,执行shell脚本时,遇到"Cannot allocate memory"的错误. 网上查询资料整理如下: Cannot allocate memory 在Linux上调试一个比较复杂的Java程序,称为JavaA吧,JavaA会频繁的通过Process proc = Runtime.getRuntime().exec(cmd);调用一些外部程序.在系统负载和该程序占用内存都比较大的情况下,会出

  • Call system command Runtime.exec () 2010-09-27

    Access to run the environment: Runtime.getRuntime () Execute the command: Runtime.getRuntime (). Exec (c) c is the specific command. Main Description c format. java api in here can only execute a command, if the need to perform multiple commands, you

  • java runtime exec 一直执行 按自己的时间停止并获取控制台数据 2014-06-09

    public class MainTest { /** * @param args */ public static void main(String[] args) { String cmd[] = {"yslow","./20140530145351_2.har"}; MainTest mt = new MainTest(); System.out.println(mt.runCommand(cmd)); } public String runCommand(S

  • Runtime Class Introduction 2010-03-23

    java.lang.Runtime.exec notes ================================================== ========= Author: lang_m (http://lang_m.itpub.net) Published on: 2006.04.22 18:57 Category: Java study notes Source: http://lang_m.itpub.net/post/4398/71874 -------------

  • Multi-threaded execution Rumtime.exec problems 2010-08-14

    Start multi-threaded implementation of ping command on a network segment, when the threads open to over 200, it is easy to report the following exceptions: Quote java.io.IOException: Cannot run program "ping": CreateProcess error = 8,? Yi ??? ×?

  • On ROWNUM and Limiting Results 2010-03-24

    On ROWNUM and Limiting Results By Tom Kyte Our technologist explains how ROWNUM works and how to make it work for you. This issue's Ask Tom column is a little different from the typical column. I receive many questions about how to perform top-N and

  • Java applications using JNI to monitor the CPU Xiangjie 2010-06-28

    How to get Java CPU The use of the situation? Here also have a good news and bad news . The bad news is not the method by using pure Java CPU Use. Do not have direct API. A suggested alternative method is through Runtime.exec() JVM process to determi

  • java online compiler (a) 2010-12-10

    See a lot of judge online software are to achieve a c, c + +, java and other languages online compilation, and the performance results back to the interactive page. Principle of a moment, and now the realization of talk about my ideas. 1. The user to

  • Android执行shell命令详解 2014-10-15

    本篇文章是对Android执行shell命令进行了详细的分析介绍,需要的朋友参考下 一.方法 /** * 执行一个shell命令,并返回字符串值 * * @param cmd * 命令名称&参数组成的数组(例如:{"/system/bin/cat", "/proc/version"}) * @param workdirectory * 命令执行路径(例如:"system/bin/") * @return 执行结果组成的字符串 * @thr

  • List of SuppressWarnings arguments 2013-11-28

    Warning Description Warning Name "Magic character" MagicCharacter "Magic number" MagicNumber 'Comparator.compare()' method does not use parameter ComparatorMethodParameterNotUsed 'Connection.prepare*()' call with non-constant string JD

  • java call the windows command 2010-03-29

    -- http://lavasoft.blog.51cto.com/62575/88507 Java call Windows commands used in two main categories: java.lang.Runtime Every Java application has a Runtime class instance, so that applications can connect to their operating environment. GetRuntime m

  • Java call linux system commands 2010-03-29

    Java can directly call the Linux command, the following forms: Runtime.getRuntime (). Exec (command) With the java command with a similar format to call the windows, and the wording on the windows a little more than briefly some. For example: java im

  • Java call linux system commands (reproduced) 2010-03-29

    Java You can directly call Linux command, as follows: Runtime.getRuntime().exec(command) And with Java call Windows command similar to the form, and style than windows briefly some slightly. Example: the java perform Linux ls command can: Java Code R

  • java modify the Windows Registry 2010-04-14

    Modify the windows registry using java keywords: java, windows, registry Used in the project, finishing as follows: Method 1: Using java.util.prefs.Preferences This is the jdk inside the built-in functions, the use of prefs package, we can process as