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

熱點內容
u盤文件給刪了 瀏覽:737
vuejsoauth2 瀏覽:78
2017微信支付日 瀏覽:81
機械臂編程如何開發 瀏覽:21
標書U盤PDF文件要不要簽字 瀏覽:222
ps軟體文件復制到d盤 瀏覽:148
一般工業固廢招標文件內容 瀏覽:583
網站建設報價怎麼算 瀏覽:66
三星a7000升級安卓502 瀏覽:486
word2010清除分隔符 瀏覽:781
樂視怎麼切換網路 瀏覽:425
cad列印pdf文件名稱與cad不一致 瀏覽:815
電氣與可編程式控制制是什麼 瀏覽:67
文件名中允許使用英文豎線嗎 瀏覽:531
編程貓在哪裡 瀏覽:775
win8共享文件夾訪問許可權 瀏覽:380
cad文件顯示為只讀不能保存怎麼辦 瀏覽:703
如何在系統里忘記網路 瀏覽:24
中小企業出口數據在哪裡找 瀏覽:715
win8和xp傳文件 瀏覽:75

友情鏈接