如何打开命令提示符并从 java 程序中输入不同的命令 [英] How to open a command prompt and input different commands from a java program

查看:23
本文介绍了如何打开命令提示符并从 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 程序中输入不同的命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆