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 程序中输入不同的命令
基础教程推荐
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
