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

熱點內容
百度網盤文件傳輸格式 瀏覽:455
蘋果系統txt文件 瀏覽:629
家裝網站怎麼設計 瀏覽:202
adc指令微程序 瀏覽:487
名片模板word 瀏覽:635
怎麼把文件夾上鎖 瀏覽:331
我不會英語怎麼編程 瀏覽:895
c盤和文件大小 瀏覽:63
maya工具架怎麼調出來 瀏覽:191
文件系統壞了怎麼辦 瀏覽:261
小公司網路布線 瀏覽:515
怎麼用二維碼編程 瀏覽:341
f9b文件能用手機看嗎 瀏覽:364
手機暴風視頻文件夾 瀏覽:394
vsftpdlinux下載文件 瀏覽:948
文件名修改後快捷方式還可以用嗎 瀏覽:387
親密愛人qq相冊名字 瀏覽:884
怎麼修改手機原始密碼 瀏覽:230
榆次網站優化怎麼樣 瀏覽:537
vb窗體文件如何打開 瀏覽:810

友情鏈接