java.io.IOException:无法运行程序错误= 2,没有这样的文件或目录

ram*_*mbo 9 csh exec

我有一个java类,我在其中调用runhellscript方法来执行脚本.它与mysql一起工作得很好,但我似乎无法找出为什么它不能与psql很好地工作.这是我的runhell方法的摘录:

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();
 }
Run Code Online (Sandbox Code Playgroud)

问题是,当我把它放在鼠标点击事件后面时,它说命令未找到.这是代码beuind the 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:
}                     
Run Code Online (Sandbox Code Playgroud)

奇怪的是,当我直接进入脚本所在的目录并输入./mysqlconnection时,脚本可以工作.但是,当我只是键入mysqlconnection时,说找不到命令.不知怎的,它没有将我的脚本名称识别为命令?

Lil*_*ung 0

在类 UNIX 系统上,如果给出了明确的路径,shell 仅执行驻留在当前目录中的程序。这是为了防止攻击者将一个名为ls您的主目录的程序放入您的主目录中,而不是驻留ls/bin/ls. 因此,当前目录被排除在 PATH 之外。

另外,尝试移动

int exitVal=process.waitFor();
Run Code Online (Sandbox Code Playgroud)

while循环上方。