run interactive command line application from java

前端 未结 2 1751
逝去的感伤
逝去的感伤 2020-12-11 02:42

I normally use java.lang.ProcessBuilder and java.lang.Process to run external command line programs, and it works fine for run-and-done commands. For example, this would run

2条回答
  •  时光取名叫无心
    2020-12-11 03:29

    Redirecting stdin and stdout is certainly one option for simple command-line programs.

    Using a "robot" class is another, if you actually need to script keystrokes (for example, in a test script):

    • http://www.java-tips.org/java-se-tips/java.awt/how-to-use-robot-class-in-java.html

    • http://download.java.net/jdk7/archive/b123/docs/api/java/awt/Robot.html

    Writing a simple .bat file or shell script, that calls your Java program and uses "<" and ">" redirection operators is yet a third option.

    It all depends on exactly what you're looking for :)

提交回复
热议问题