導航:首頁 > 編程語言 > java調用exe傳參數

java調用exe傳參數

發布時間:2021-03-12 15:48:43

java如何調用exe文件

public class transferExe {
public static void main(String[] args) {
openWinExe();
openExe();
}
//用 Java 調用windows系統的exe文件,比如notepad,calc之類
public static void openWinExe() {
Runtime rn = Runtime.getRuntime();
Process p = null;
try {
String command = "notepad";
p = rn.exec(command);
} catch (Exception e) {
System.out.println("Error win exec!");
}
}
//調用其他的可執行文件,例如:自己製作的exe,或是 下載 安裝的軟體.
public static void openExe() {
Runtime rn = Runtime.getRuntime();
Process p = null;
try {
p = rn.exec("\"D:/QQ2010.exe\"");
} catch (Exception e) {
System.out.println("Error exec!");
}
}
}

Ⅱ java程序里用runtime調用上級目錄下的EXE文件,並且有參數命令,如何使用相對路徑

那就把exe上傳到項目里,然後用程序在項目中的路徑,這樣就不必改來改去了。當然你也可以採用配置的方法,譬如properties文件,把位置信息存在properties文件中,路徑動態的讀取出來,同樣可以達到目的。

Ⅲ java中如何執行帶參數的exe程序,還有如何執行dos命令,比如打開文件夾「cd 」.

你可以查看api幫助文檔

Ⅳ 怎樣在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後台啟動本地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 怎麼傳遞參數

public class Test {
public static void main(String[] args) throws IOException {
try {
// 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 需要給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調用bat文件傳入參數,急,急,急!

java好像不能直接給bat文件傳參數,不過你可以先生成一個你需要的bat文件,再去執行這個bat文件,我就是這么做的,給你寫了個例子,你參考下(你先在d盤下建一個text.txt)
public class DelFile {
public void creatBat(String command){
FileWriter fw=null;
try {
fw=new FileWriter("D:\\del.bat");
fw.write(command);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.exit(0);
}finally{
if(fw!=null){
try {
fw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.exit(0);
}
}
}
}

private String execute(String batname){
Process process;
String line = null;
StringBuffer sb=new StringBuffer();
try {
process = Runtime.getRuntime().exec(batname);
InputStream fis = process.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
while ((line = br.readLine()) != null) {
System.out.println(line);
}
if(process.waitFor()!=0){
System.out.println("fail");
return "fail";
}
System.out.println(batname+" run successful!");
return "success";
} catch (Exception e) {
e.printStackTrace();
return "fail";
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
DelFile df=new DelFile();
df.creatBat("del D:\\text.txt");
df.execute("D:\\del.bat");
}

}

Ⅸ java中Runtime.exe執行時怎麼傳入參數

你好!
爭議首先要有一個密碼password
然後與輸入的密碼匹配
if(password
=
inpassword)
Process
pro=Runtime.getRuntime().exec("exe文件的路徑");
不匹配就不執行
我的回答你還滿意嗎~~

Ⅹ java如何調用exe文件

public class transferExe {
public static void main(String[] args) {
openWinExe();
openExe();
}
//用 Java 調用windows系統的exe文件,比如,calc之類
public static void openWinExe() {
Runtime rn = Runtime.getRuntime();
Process p = null;
try {
String command = "notepad";
p = rn.exec(command);
} catch (Exception e) {
System.out.println("Error win exec!");
}
}
//調用其他的可執行文件,例如:自己製作的exe,或是 下載 安裝的軟體.
public static void openExe() {
Runtime rn = Runtime.getRuntime();
Process p = null;
try {
p = rn.exec("\"D:/QQ2010.exe\"");
} catch (Exception e) {
System.out.println("Error exec!");
}
}
}

閱讀全文

與java調用exe傳參數相關的資料

熱點內容
從哪裡可以下載a股的數據 瀏覽:437
邏輯文件名和物理文件名關系 瀏覽:66
怎麼查一個網站的外鏈 瀏覽:675
linux下db2安裝時版本選擇 瀏覽:738
匯編編程用哪個軟體 瀏覽:486
仙樂下的歌在文件管理哪裡 瀏覽:477
115網盤解析工具2014 瀏覽:371
內圓弧銑刀怎麼編程 瀏覽:410
記事本文件轉word格式對齊 瀏覽:300
excel刪除恢復文件 瀏覽:290
三星s4怎麼切換3g網路 瀏覽:994
什麼是網站維護 瀏覽:314
文件夾錄像在哪裡 瀏覽:621
可以發語音的是什麼app 瀏覽:804
恢復手機桌面文件管理 瀏覽:627
用什麼軟體可以打開psd文件 瀏覽:459
公安有哪些警務app 瀏覽:150
生意轉租用什麼app 瀏覽:683
廣義的網路信息保密性是指 瀏覽:657
qq背景唯美簡約圖片 瀏覽:292

友情鏈接