How to open a command prompt and input different commands from a java program(如何打开命令提示符并从 java 程序中输入不同的命令)
问题描述
我需要打开一个命令提示符 &执行 ij.bat
,这将带我到另一个提示,我可以在其中发出命令以连接到 DB &后来不同的sql语句.我能够从像
I need to open a command prompt & execute ij.bat
, which will take me to another prompt, where I can give command to connect to DB & later different sql statements. I was able to execute ij.bat
from the java program like
进程进程 = Runtime.getRuntime().exec("D:\ij.bat");
但是如何通过java程序给出更多的命令呢?
But how to give the furthur set of commands through the java program?
推荐答案
不要尝试运行 ij.bat 并为其提供命令来运行和解析输出,只需让您的程序使用 ij 类及其 runScript 方法:http://db.apache.org/derby/docs/10.11/publishedapi/org/apache/derby/tools/ij.html#runScript-java.sql.Connection-java.io.InputStream-java.lang.String-java.io.OutputStream-java.lang.String-
Instead of trying to run ij.bat, and feed it commands to run and parse the output, just have your program use the ij class, and its runScript method: http://db.apache.org/derby/docs/10.11/publishedapi/org/apache/derby/tools/ij.html#runScript-java.sql.Connection-java.io.InputStream-java.lang.String-java.io.OutputStream-java.lang.String-
那么您不必生成一个单独的进程,而可以在您的程序本身中以纯 Java 的形式保存所有内容.
Then you don't have to spawn a separate process, but can just keep everything in pure Java in your program itself.
这篇关于如何打开命令提示符并从 java 程序中输入不同的命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何打开命令提示符并从 java 程序中输入不同的命令


基础教程推荐
- 不推荐使用 Api 注释的描述 2022-01-01
- 多个组件的复杂布局 2022-01-01
- 验证是否调用了所有 getter 方法 2022-01-01
- Java 实例变量在两个语句中声明和初始化 2022-01-01
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
- 在 Java 中创建日期的正确方法是什么? 2022-01-01
- 从 python 访问 JVM 2022-01-01
- 大摇大摆的枚举 2022-01-01
- Java Swing计时器未清除 2022-01-01
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01