導航:首頁 > 編程語言 > 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並加參數相關的資料

熱點內容
app直通車是什麼意思 瀏覽:710
cad文件怎麼輸出為wmf文件 瀏覽:137
bat批量重命名word文件 瀏覽:64
汽車安卓導航懸浮 瀏覽:481
ps用快速蒙版調文件里黑白色 瀏覽:746
蘋果6iphone解鎖無法開啟 瀏覽:201
高通模式線刷工具 瀏覽:40
打開pDF顯示檢查文件許可權 瀏覽:825
怎麼刪除文件名中指定字元 瀏覽:595
圖片如何轉化文件格式 瀏覽:859
無貨源鋪貨有哪些app 瀏覽:316
30g的文件可以保存在哪裡 瀏覽:329
不同文件夾的pdf怎麼批量拆分 瀏覽:98
順豐速運文件到付多少錢 瀏覽:892
安裝的app在哪裡看 瀏覽:773
流量包和數據包什麼區別 瀏覽:851
編程語言事先定義好是什麼意思 瀏覽:919
怎麼轉換qlv文件 瀏覽:516
大眾網關版本 瀏覽:832
編程為什麼要用佔位符 瀏覽:108

友情鏈接