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

查看:235
本文介绍了如何打开命令提示符并从java程序中输入不同的命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要打开命令提示符&执行 ij.bat ,这将带我到另一个提示,其中我可以命令连接到DB&后来不同的sql语句。我可以从java程序执行 ij.bat ,如

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

Process process = Runtime.getRuntime()。exec(D:\\ij.bat);

但是如何给予furthur集的命令通过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天全站免登陆