导航:首页 > 编程语言 > java调用exe传参数

java调用exe传参数

发布时间:2021-03-12 15:48:43

java如何调用exe文件

public class transferExe {
public static void main(String[] args) {
openWinExe();
openExe();
}
//用 Java 调用windows系统的exe文件,比如notepad,calc之类
public static void openWinExe() {
Runtime rn = Runtime.getRuntime();
Process p = null;
try {
String command = "notepad";
p = rn.exec(command);
} catch (Exception e) {
System.out.println("Error win exec!");
}
}
//调用其他的可执行文件,例如:自己制作的exe,或是 下载 安装的软件.
public static void openExe() {
Runtime rn = Runtime.getRuntime();
Process p = null;
try {
p = rn.exec("\"D:/QQ2010.exe\"");
} catch (Exception e) {
System.out.println("Error exec!");
}
}
}

Ⅱ java程序里用runtime调用上级目录下的EXE文件,并且有参数命令,如何使用相对路径

那就把exe上传到项目里,然后用程序在项目中的路径,这样就不必改来改去了。当然你也可以采用配置的方法,譬如properties文件,把位置信息存在properties文件中,路径动态的读取出来,同样可以达到目的。

Ⅲ java中如何执行带参数的exe程序,还有如何执行dos命令,比如打开文件夹“cd ”.

你可以查看api帮助文档

Ⅳ 怎样在java类中调用带参数的可执行文件(比如:.exe,.sh等等)

比如调用exe程序"java -version":

String[] cmd = new String[] {"java", "-version"};
Process process = Runtime.getRuntime().exec(cmd);
BufferedReader r = new BufferedReader(new InputStreamReader(process.getErrorStream()));
String l = null;
while((l = r.readLine()) != null) {
System.out.println(l);
}

Process有两个流可以读取外部程序的标准输出(就是运行结果啦),一个是getInputStream,一个是getErrorStream。

如果要调用C或C++动态链接库中的函数的话,就要复杂一些,要用到JNI了。

Ⅳ JAVA后台启动本地exe程序如何传递参数到exe程序并接收

List<String> commands = new ArrayList();

commands.add("a.exe");
commands.add("abc");
ProcessBuilder pb = new ProcessBuilder();
pb.command(commands);
Process pr = pb.start();

Ⅵ java 调用exe 怎么传递参数

public class Test {
public static void main(String[] args) throws IOException {
try {
// String[] cmds = {"cmd.exe","/c"," dir","c:",">","d://aa.txt"};
// Process pro = Runtime.getRuntime().exec(cmds);
Process pro = Runtime.getRuntime().exec("cmd.exe /c dir c: > d://aa.txt");

BufferedReader br = new BufferedReader(new InputStreamReader(pro.getInputStream(),"GBK"));
String msg = null;
while ((msg = br.readLine()) != null) {
System.out.println(msg);
}
} catch (IOException exception) {
}
}
}

执行完成之后 会在d://下面生成一个aa.txt文件 里面保存了 dir的结果 其中 > 是 重定向 意思是讲执行结果从定向到 d://aa.txt

Ⅶ java 调用exe 需要给exe传参数

public class Test {
public static void main(String[] args) throws IOException {
{
// String[] cmds = {"cmd.exe","/c"," dir","c:",">","d://aa.txt"};
// Process pro = Runtime.getRuntime().exec(cmds);
Process pro = Runtime.getRuntime().exec("cmd.exe /c dir c: > d://aa.txt");

BufferedReader br = new BufferedReader(new InputStreamReader(pro.getInputStream(),"GBK"));
String msg = null;
while ((msg = br.readLine()) != null) {
System.out.println(msg);
}
} catch (IOException exception) {
}
}
}

执行完成之后 会在d://下面生成一个aa.txt文件 里面保存了 dir的结果 其中 > 是 重定向 意思是讲执行结果从定向到 d://aa.txt
希望对你有帮助

Ⅷ java调用bat文件传入参数,急,急,急!

java好像不能直接给bat文件传参数,不过你可以先生成一个你需要的bat文件,再去执行这个bat文件,我就是这么做的,给你写了个例子,你参考下(你先在d盘下建一个text.txt)
public class DelFile {
public void creatBat(String command){
FileWriter fw=null;
try {
fw=new FileWriter("D:\\del.bat");
fw.write(command);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.exit(0);
}finally{
if(fw!=null){
try {
fw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.exit(0);
}
}
}
}

private String execute(String batname){
Process process;
String line = null;
StringBuffer sb=new StringBuffer();
try {
process = Runtime.getRuntime().exec(batname);
InputStream fis = process.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
while ((line = br.readLine()) != null) {
System.out.println(line);
}
if(process.waitFor()!=0){
System.out.println("fail");
return "fail";
}
System.out.println(batname+" run successful!");
return "success";
} catch (Exception e) {
e.printStackTrace();
return "fail";
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
DelFile df=new DelFile();
df.creatBat("del D:\\text.txt");
df.execute("D:\\del.bat");
}

}

Ⅸ java中Runtime.exe执行时怎么传入参数

你好!
争议首先要有一个密码password
然后与输入的密码匹配
if(password
=
inpassword)
Process
pro=Runtime.getRuntime().exec("exe文件的路径");
不匹配就不执行
我的回答你还满意吗~~

Ⅹ java如何调用exe文件

public class transferExe {
public static void main(String[] args) {
openWinExe();
openExe();
}
//用 Java 调用windows系统的exe文件,比如,calc之类
public static void openWinExe() {
Runtime rn = Runtime.getRuntime();
Process p = null;
try {
String command = "notepad";
p = rn.exec(command);
} catch (Exception e) {
System.out.println("Error win exec!");
}
}
//调用其他的可执行文件,例如:自己制作的exe,或是 下载 安装的软件.
public static void openExe() {
Runtime rn = Runtime.getRuntime();
Process p = null;
try {
p = rn.exec("\"D:/QQ2010.exe\"");
} catch (Exception e) {
System.out.println("Error exec!");
}
}
}

阅读全文

与java调用exe传参数相关的资料

热点内容
从哪里可以下载a股的数据 浏览:437
逻辑文件名和物理文件名关系 浏览:66
怎么查一个网站的外链 浏览:675
linux下db2安装时版本选择 浏览:738
汇编编程用哪个软件 浏览:486
仙乐下的歌在文件管理哪里 浏览:477
115网盘解析工具2014 浏览:371
内圆弧铣刀怎么编程 浏览:410
记事本文件转word格式对齐 浏览:300
excel删除恢复文件 浏览:290
三星s4怎么切换3g网络 浏览:994
什么是网站维护 浏览:314
文件夹录像在哪里 浏览:621
可以发语音的是什么app 浏览:804
恢复手机桌面文件管理 浏览:627
用什么软件可以打开psd文件 浏览:459
公安有哪些警务app 浏览:150
生意转租用什么app 浏览:683
广义的网络信息保密性是指 浏览:657
qq背景唯美简约图片 浏览:292

友情链接