我有一个 java 类,我在其中调用一个 runshellscript 方法来执行脚本。它适用于 mysql,但我似乎无法找出为什么它不适用于 psql。这是我的 runshell 方法的摘录:
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();
}
问题是当我把它放在鼠标点击事件后面时,它说找不到命令。这是mous事件的代码
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 时说找不到命令。不知何故,它没有将我的脚本名称识别为命令?