📄 runtime.java
字号:
* * throws SecurityException * if a security manager exists and its <code>checkExit</code> * method doesn't allow the exit. * * see java.lang.Runtime#exit(int) * see java.lang.Runtime#gc() * see java.lang.SecurityManager#checkExit(int) * since JDK1.1 * public static void runFinalizersOnExit(boolean value) { SecurityManager security = System.getSecurityManager(); if (security != null) { try { security.checkExit(0); } catch (SecurityException e) { throw new SecurityException("runFinalizersOnExit"); } } Shutdown.setRunFinalizersOnExit(value); } */ /* Helper for exec */ private native Process execInternal(String cmdarray[], String envp[], String path) throws IOException; /** * Executes the specified string command in a separate process. * <p> * The <code>command</code> argument is parsed into tokens and then * executed as a command in a separate process. The token parsing is * done by a {@link java.util.StringTokenizer} created by the call: * <blockquote><pre> * new StringTokenizer(command) * </pre></blockquote> * with no further modifications of the character categories. * This method has exactly the same effect as * <code>exec(command, null)</code>. * <p> * If process model exists, Runtime.exec() must behave as it * does in the J2SE specification. * <p> * If process model does not exist, Runtime.exec() and all * java.lang.Process methods must throw SecurityException. * <p> * * @param command a specified system command. * @return a <code>Process</code> object for managing the subprocess. * @exception SecurityException if a security manager exists and its * <code>checkExec</code> method doesn't allow creation of a subprocess. * @exception IOException if an I/O error occurs * @exception NullPointerException if <code>command</code> is * <code>null</code> * @exception IllegalArgumentException if <code>command</code> is empty * * @see java.lang.Runtime#exec(java.lang.String, java.lang.String[]) * @see java.lang.SecurityManager#checkExec(java.lang.String) */ public Process exec(String command) throws IOException { return exec(command, null); } /** * Executes the specified string command in a separate process with the * specified environment. * <p> * This method breaks the <code>command</code> string into tokens and * creates a new array <code>cmdarray</code> containing the tokens in the * order that they were produced by the string tokenizer; it * then performs the call <code>exec(cmdarray, envp)</code>. The token * parsing is done by a {@link java.util.StringTokenizer} created by * the call: * <blockquote><pre> * new StringTokenizer(command) * </pre></blockquote> * with no further modification of the character categories. * * <p> * The environment variable settings are specified by <tt>envp</tt>. * If <tt>envp</tt> is <tt>null</tt>, the subprocess inherits the * environment settings of the current process. * <p> * If process model exists, Runtime.exec() must behave as it * does in the J2SE specification. * <p> * If process model does not exist, Runtime.exec() and all * java.lang.Process methods must throw SecurityException. * <p> * * @param cmd a specified system command. * @param envp array of strings, each element of which * has environment variable settings in format * <i>name</i>=<i>value</i>. * @return a <code>Process</code> object for managing the subprocess. * @exception SecurityException if a security manager exists and its * <code>checkExec</code> method doesn't allow creation of a subprocess. * @exception IOException if an I/O error occurs * @exception NullPointerException if <code>cmd</code> is null * @exception IllegalArgumentException if <code>cmd</code> is empty * @see java.lang.Runtime#exec(java.lang.String[]) * @see java.lang.Runtime#exec(java.lang.String[], java.lang.String[]) * @see java.lang.SecurityManager#checkExec(java.lang.String) */ public Process exec(String cmd, String envp[]) throws IOException { return exec(cmd, envp, null); } /** * Executes the specified string command in a separate process with the * specified environment and working directory. * <p> * This method breaks the <code>command</code> string into tokens and * creates a new array <code>cmdarray</code> containing the tokens in the * order that they were produced by the string tokenizer; it * then performs the call <code>exec(cmdarray, envp)</code>. The token * parsing is done by a {@link java.util.StringTokenizer} created by * the call: * <blockquote><pre> * new StringTokenizer(command) * </pre></blockquote> * with no further modification of the character categories. * * <p> * The environment variable settings are specified by <tt>envp</tt>. * If <tt>envp</tt> is <tt>null</tt>, the subprocess inherits the * environment settings of the current process. * * <p> * The working directory of the new subprocess is specified by <tt>dir</tt>. * If <tt>dir</tt> is <tt>null</tt>, the subprocess inherits the * current working directory of the current process. * * <p> * If process model exists, Runtime.exec() must behave as it * does in the J2SE specification. * <p> * If process model does not exist, Runtime.exec() and all * java.lang.Process methods must throw SecurityException. * <p> * * @param command a specified system command. * @param envp array of strings, each element of which * has environment variable settings in format * <i>name</i>=<i>value</i>. * @param dir the working directory of the subprocess, or * <tt>null</tt> if the subprocess should inherit * the working directory of the current process. * @return a <code>Process</code> object for managing the subprocess. * @exception SecurityException if a security manager exists and its * <code>checkExec</code> method doesn't allow creation of a subprocess. * @exception IOException if an I/O error occurs * @exception NullPointerException if <code>command</code> is * <code>null</code> * @exception IllegalArgumentException if <code>command</code> is empty * @see java.lang.Runtime#exec(java.lang.String[], java.lang.String[], File) * @see java.lang.SecurityManager#checkExec(java.lang.String) * @since 1.3 */ public Process exec(String command, String envp[], File dir) throws IOException { int count = 0; String cmdarray[]; StringTokenizer st; if (command.length() == 0) throw new IllegalArgumentException("Empty command"); st = new StringTokenizer(command); count = st.countTokens(); cmdarray = new String[count]; st = new StringTokenizer(command); count = 0; while (st.hasMoreTokens()) { cmdarray[count++] = st.nextToken(); } return exec(cmdarray, envp, dir); } /** * Executes the specified command and arguments in a separate process. * <p> * The command specified by the tokens in <code>cmdarray</code> is * executed as a command in a separate process. This has exactly the * same effect as <code>exec(cmdarray, null)</code>. * <p> * If there is a security manager, its <code>checkExec</code> * method is called with the first component of the array * <code>cmdarray</code> as its argument. This may result in a security * exception. * * <p> * If process model exists, Runtime.exec() must behave as it * does in the J2SE specification. * <p> * If process model does not exist, Runtime.exec() and all * java.lang.Process methods must throw SecurityException. * <p> * * @param cmdarray array containing the command to call and * its arguments. * @return a <code>Process</code> object for managing the subprocess. * @exception SecurityException if a security manager exists and its * <code>checkExec</code> method doesn't allow creation of a subprocess. * @exception IOException if an I/O error occurs * @exception NullPointerException if <code>cmdarray</code> is * <code>null</code> * @exception IndexOutOfBoundsException if <code>cmdarray</code> is an * empty array (has length <code>0</code>). * @see java.lang.Runtime#exec(java.lang.String[], java.lang.String[]) * @see java.lang.SecurityManager#checkExec(java.lang.String) */ public Process exec(String cmdarray[]) throws IOException { return exec(cmdarray, null); } /** * Executes the specified command and arguments in a separate process * with the specified environment. * <p> * Given an array of strings <code>cmdarray</code>, representing the * tokens of a command line, and an array of strings <code>envp</code>, * representing "environment" variable settings, this method creates * a new process in which to execute the specified command. * * <p> * If <tt>envp</tt> is <tt>null</tt>, the subprocess inherits the * environment settings of the current process. * * <p> * If process model exists, Runtime.exec() must behave as it * does in the J2SE specification. * <p> * If process model does not exist, Runtime.exec() and all * java.lang.Process methods must throw SecurityException. * <p> * * @param cmdarray array containing the command to call and * its arguments. * @param envp array of strings, each element of which * has environment variable settings in format * <i>name</i>=<i>value</i>. * @return a <code>Process</code> object for managing the subprocess. * @exception SecurityException if a security manager exists and its * <code>checkExec</code> method doesn't allow creation of a subprocess. * @exception IOException if an I/O error occurs * @exception NullPointerException if <code>cmdarray</code> is * <code>null</code> * @exception IndexOutOfBoundsException if <code>cmdarray</code> is an * empty array (has length <code>0</code>). * @see java.lang.Process * @see java.lang.SecurityException * @see java.lang.SecurityManager#checkExec(java.lang.String) */ public Process exec(String cmdarray[], String envp[]) throws IOException { return exec(cmdarray, envp, null); } /** * Executes the specified command and arguments in a separate process with * the specified environment and working directory. * <p> * If there is a security manager, its <code>checkExec</code> * method is called with the first component of the array * <code>cmdarray</code> as its argument. This may result in a security * exception. * <p> * Given an array of strings <code>cmdarray</code>, representing the * tokens of a command line, and an array of strings <code>envp</code>, * representing "environment" variable settings, this method creates * a new process in which to execute the specified command. * * <p> * If <tt>envp</tt> is <tt>null</tt>, the subprocess inherits the * environment settings of the current process. * * <p> * The working directory of the new subprocess is specified by <tt>dir</tt>. * If <tt>dir</tt> is <tt>null</tt>, the subprocess inherits the * current working directory of the current process. * * * <p> * If process model exists, Runtime.exec() must behave as it * does in the J2SE specification. * <p> * If process model does not exist, Runtime.exec() and all * java.lang.Process methods must throw SecurityException. * <p> * * @param cmdarray array containing the command to call and * its arguments. * @param envp array of strings, each element of which * has environment variable settings in format * <i>name</i>=<i>value</i>. * @param dir the working directory of the subprocess, or * <tt>null</tt> if the subprocess should inherit * the working directory of the current process. * @return a <code>Process</code> object for managing the subprocess. * @exception SecurityException if a security manager exists and its * <code>checkExec</code> method doesn't allow creation of a * subprocess. * @exception NullPointerException if <code>cmdarray</code> is * <code>null</code> * @exception IndexOutOfBoundsException if <code>cmdarray</code> is an * empty array (has length <code>0</code>). * @exception IOException if an I/O error occurs. * @see java.lang.Process * @see java.lang.SecurityException
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -