为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

C PHP
守着星空守着你 2021-12-02 11:11:01
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等。
查看完整描述

1 回答

?
MYYA

TA贡献1868条经验 获得超4个赞

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).

查看完整回答
反对 回复 2021-12-06
  • 1 回答
  • 0 关注
  • 377 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信