⑴ java程序里用runtime调用上级目录下的EXE文件,并且有参数命令,如何使用相对路径
那就把exe上传到项目里,然后用程序在项目中的路径,这样就不必改来改去了。当然你也可以采用配置的方法,譬如properties文件,把位置信息存在properties文件中,路径动态的读取出来,同样可以达到目的。
⑵ 如何用批处理调用exe程序把参数传递给其他文件
要在批处理中调用exe程序并将参数传递给其他文件,可以使用以下步骤:
在批处理文件中使用start命令调用exe程序,例如:
sql
start "My Program" "C:Program FilesMyProgramMyProgram.exe"
这会启动名为"My Program"的窗口,并执行"C:Program FilesMyProgramMyProgram.exe"可执行文件。
如果要将参数传递给exe程序,可以在exe程序路径后面加上参数,例如:
sql
start "My Program" "C:Program FilesMyProgramMyProgram.exe" arg1 arg2 arg3
这会将三个参数arg1、arg2和arg3传递给MyProgram.exe程序。
在exe程序中,可以使用命令行参数获取批处理传递的参数。在C++中,可以使用main函数的参数来获取这些参数,例如:
c++
int main(int argc, char* argv[]){ // 获取参数个数
这样就可以将批处理传递的参数在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
希望对你有帮助