我有一个java类,我在其中调用runhellscript方法来执行脚本。它与mysql一起运行良好,但我似乎无法找出为什么它不能与psql很好地工作。这是我的runhell方法的摘录
public static void runShellScript (String unixCommand)
{
try {
Runtime runtime=Runtime.getRuntime();
Process process=runtime.exec(new String [] { "/bin/csh", "-c", 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 the mous事件
private void jMenuItem6MousePressed(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
String shellCommand="/vobs/tools/DataValidation/mysqlconnection.csh";
// RunShellScript run=new RunShellScript();
RunShellScript.runShellScript(shellCommand);
}
奇怪的是,当我直接进入脚本所在的目录并输入./mysqlconnection时,脚本可以工作。但是,当我只是键入mysqlconnection时,说找不到命令。不知怎的,它没有将我的脚本名称识别为命令?