我有一個Java類,我在其中調用runshellscript方法,將執行腳本。它與mysql運行良好,但我似乎無法找出爲什麼它不適用於psql。這裏是我的runshell方法的摘錄:java.io.IOException:無法運行程序錯誤= 2,沒有這樣的文件或目錄
public class RunShellScript {
public static void runShellScript (String unixCommand)
{
try {
Runtime runtime=Runtime.getRuntime();
//Process process=runtime.exec(new String [] { "/bin/csh", "-c", unixCommand});
Process process=runtime.exec(new String [] {unixCommand});
InputStream stderr=process.getErrorStream();
InputStreamReader isr=new InputStreamReader (stderr);
BufferedReader br=new BufferedReader (isr);
String line=null;
System.out.println("<ERROR>");
while((line=br.readLine())!=null)
System.out.println(line);
System.out.println(line);
int exitVal=process.waitFor();
System.out.println("Process exitValue:" + exitVal);
}
catch (Throwable t)
{
t.printStackTrace();
}
問題是,當我把它放在一個鼠標點擊事件後它說沒有找到命令。這裏是代碼beuind諒解備忘錄事件
private void jMenuItem13MousePressed(java.awt.event.MouseEvent evt) {
String shellCommand="vobs/tools/Scripts/DataValidation/mysqlconnection.csh";
RunShellScript.runShellScript(shellCommand);
// TODO add your handling code here:
}
奇怪的是,當我直接進入目錄的腳本所在的位置和類型./mysqlconnection劇本的作品。但是,當我只鍵入mysqlconnection是說找不到命令。不知何故,它不認可我的腳本名稱作爲命令?
所以我應該補充的路徑,在我的CSH腳本path變量 – rambokayambo 2012-08-03 00:21:30
您應該使用'。在你的代碼/ mysqlconnection'代替'mysqlconnection' – ikdc 2012-08-03 00:22:59
我試過......但它不工作。所以你建議我分配我的字符串變量的路徑應該是vobs/tools/Scripts/DataValidation/.mysqlconnection.csh「; – rambokayambo 2012-08-03 00:25:46