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

熱點內容
950底欄代碼 瀏覽:983
cnc圓弧怎麼樣編程 瀏覽:199
java二叉堆 瀏覽:850
少兒編程後會怎麼樣 瀏覽:783
ps去掉掃描文件無效部分 瀏覽:191
快速創建文件夾路徑路徑 瀏覽:849
京東app虛擬試衣 瀏覽:136
三星電視智能升級卡 瀏覽:327
word文件字型大小 瀏覽:460
word文檔去除下劃線 瀏覽:576
貝多芬交響曲版本 瀏覽:532
下載的視頻文件損壞了 瀏覽:119
怎麼把jpg轉成cad格式的文件大小 瀏覽:674
如何編程真人快打 瀏覽:57
double運行數據最長多少 瀏覽:367
tr90如何看數據 瀏覽:418
word裡面插了一個文件怎麼打開 瀏覽:40
蘋果7限時秒殺1999元 瀏覽:748
如何提升app推送觸達率 瀏覽:584
vba用kill刪除文件路徑錯誤 瀏覽:648

友情鏈接