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

熱點內容
怎麼轉換qlv文件 瀏覽:516
大眾網關版本 瀏覽:832
編程為什麼要用佔位符 瀏覽:108
bat批量創建文件 瀏覽:713
學編程的最強的奧義是什麼 瀏覽:336
access怎麼導出資料庫文件 瀏覽:356
谷歌瀏覽器怎麼清理緩存文件在哪裡 瀏覽:59
java實現數據圖表分析 瀏覽:80
arm9怎麼用c編程 瀏覽:52
手機連接wifi怎樣分享wifi密碼 瀏覽:980
泉城辦app怎麼樣 瀏覽:7
蘋果6用什麼手機助手 瀏覽:470
怎麼用qq查看騰訊微博賬號密碼 瀏覽:945
ipadmobi文件怎麼打開 瀏覽:751
extjs6storeload 瀏覽:579
如何在rtk中導入cad文件 瀏覽:748
linux轉pdf文件 瀏覽:607
如何查看自家網路流量被盜用 瀏覽:174
電腦外網共享看不到文件 瀏覽:34
香港有2g網路嗎 瀏覽:754

友情鏈接