有谁知道Runtime.getRuntime().exec()的具体用法?请求帮忙看看

import javax.swing.*; import javax.swing.event.*; import java.awt.*; import java.awt.event.*; import java.io.*; public class Robot05{ //Create an array of keycode data static int keyInput[] = { KeyEvent.VK_H, KeyEvent.VK_E, KeyEvent.VK_L, KeyEvent.VK_L, KeyEvent.VK_O };//end keyInput array public static void main(String[] args) throws AWTException,IOException{ Runtime.getRuntime().exec("notepad"); Robot robot = new Robot(); robot.keyPress(KeyEvent.VK_SHIFT); for (int cnt2 = 0;cnt2 < keyInput.length; cnt2++){ if(cnt2 > 0){ robot.keyRelease(KeyEvent.VK_SHIFT); }//end if robot.keyPress(keyInput[cnt2]); //Insert a one-half second delay between // characters. robot.delay(500); }//end for loop }//main }//end class Robot05 我想把这里的notepad改成其他的程序,比如cmd,java shell等。

守着星空守着你
浏览 378回答 1
1回答

MYYA

public Process exec(String[] cmdarray) throws IOException Executes the specified command and arguments in a separate process. The command specified by the tokens in cmdarray is executed as a command in a separate process. This has exactly the same effect as exec(cmdarray, null). If there is a security manager, its checkExec method is called with the first component of the array cmdarray as its argument. This may result in a security exception. Parameters: cmdarray - array containing the command to call and its arguments. Returns: a Process object for managing the subprocess. Throws: SecurityException - if a security manager exists and its checkExec method doesn't allow creation of a subprocess. IOException - if an I/O error occurs NullPointerException - if cmdarray is null IndexOutOfBoundsException - if cmdarray is an empty array (has length 0).
打开App,查看更多内容
随时随地看视频慕课网APP