我在eclipse中使用Runtime.getRuntime()。exec來從當前程序運行另一個java程序。 我用下面的代碼。在eclipse中使用Runtime.getRuntime()。exec
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
System.out.println("Enter the class name");
String s=br.readLine();
String str="XYZ";
String[] cmd = {"java","-cp", "C:/Users/..../workspace/Testing/bin",s,str};
Process pro=Runtime.getRuntime().exec(cmd);
我還將一個字符串「XYZ」傳遞給該程序。該程序只接受的字符串和顯示
你的字符串是XYZ
但是,通過使用線
字符串[] CMD = { 「java的」, 「 - CP」, 「C:/ Users /..../ workspace/Testing/bin」,s,str};
我能夠運行該程序,但它不接受任何參數。它既不顯示輸出也不顯示任何錯誤。
我哪裏錯了?
審議該方案被稱爲是
import java.io.*;
public class Test
{
public static void main(String[] args) throws IOException
{
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
System.out.println("Enter any string");
String s=br.readLine();
System.out.println("Your string is "+s);
}
}
這個程序應該接受字符串XYZ,並打印你的字符串是XYZ
爲了記錄在案,如果你手工執行Eclipse外的exe進程是否能夠正常工作? – Grambot
@TheCapn:執行正在和沒有日食,但我不能通過任何參數在兩種方式 – Anil
我懷疑這個問題是你正在調用的程序。你有源代碼嗎?還是更多的黑盒操作? – Grambot