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

java调用exe并加参数

发布时间:2023-03-23 20:15:36

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

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

⑵ 如何用批处理调用exe程序把参数传递给其他文件

要在批处理中调用exe程序并将参数传递给其他文件,可以使用以下步骤:

⑶ 要怎么用java代码启动带参数的.exe程序大神求解呀 百度了好多都没有答案

java调闹陆用winrar命令的:
String cmd = "C:\\Program Files\\WinRAR\\winrar.exe x -r -o+ -ibck -y "
+ oldFile + " *.* " + tmp;
Runtime rt = Runtime.getRuntime();
Process pre = rt.exec(cmd); //核心就这液耐顷两行就行了亩庆。

cmd是winrar命令的规则和参数来凑的。给个例子链接:
http://blog.csdn.net/java2010czp/article/details/7231315

⑷ 怎样在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调用C的EXE程序并且实现程序自动输入

import java.io.*;
import java.lang.*;
import java.nio.charset.*;
public class Rt
{
public static void main(String[] args) throws Exception
{
if( args.length == 0 ) {
System.out.println("用法: java Rt <目标EXE> <提供给的参数...>");
return;
}
Runtime rt = Runtime.getRuntime();

ProcessBuilder pb = new ProcessBuilder(args);
Process p = pb.start();
p.waitFor();
int exitCode = p.exitValue();
System.out.println("exitCode = " + exitCode);
InputStream resultStream = p.getInputStream();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
int size, SIZE = 4096;
byte[] buffer = new byte[SIZE];
while( (size = resultStream.read(buffer)) != -1 ) {
outputStream.write(buffer, 0, size);
}
byte[] bytes = outputStream.toByteArray();
outputStream.close();
String str = new String(bytes);
System.out.println(str);
}
/*
#include <stdio.h>
int main(int argc, char *argv[])
{
int i = 0;
printf("argc = %d\n", argc);
for(i = 0; i < argc; i ++)
printf("argv[%d] = %s\n", i, argv[i]);
return 0;
}
*/
}

⑹ exe文件如何加参数运行

1、首先进入exe文件位置,右键单击文件。

⑺ 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 需要给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调用exe并加参数相关的资料

热点内容
微信玩红包怎么定大小 浏览:825
电脑病毒测试代码 浏览:118
得物app为什么总是更新 浏览:965
银企对账程序 浏览:164
r读取excel文件 浏览:363
上古卷轴5控制台附魔代码 浏览:514
缓存文件合并找不到文件 浏览:871
桌面保存一下文件找不到 浏览:645
程序美工标准 浏览:191
漂流瓶的文件在哪里 浏览:319
数据的正负偏差怎么计算 浏览:242
文件名用不用带TXT 浏览:968
小米十数据线是哪个 浏览:463
caddws文件 浏览:962
js获取复选框是否选中 浏览:289
wps查文件路径 浏览:28
ps作图完成后怎么保存文件 浏览:429
文件路径是怎么产生的 浏览:947
word最后一行对不齐 浏览:743
股字程序 浏览:492

友情链接