0

I have a java class in which i call a runshellscript method that will execute a script. It worked well with mysql but i cannot seem to find out why it wont work well with psql. Here is an excerpt of my runshell method

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();
 }

the problem is that when i put this behind a mouse clicked event it says command not found. Here is the code beuind the mous event

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);

}      

the wierd thing is that when i go directly to the directory where the script resides and type ./mysqlconnection the script works. But when i just type mysqlconnection is says command not found. Somehow it is not recognizing my script name as a command?

rambokayambo
  • 341
  • 4
  • 10
  • 27
  • does it say '.... mysqlconection.csh not found' OR 'myql not found'? Your script probably doesn't have the path to mysql set, and it is msql that is the 'command not found', not your .csh script. Add a `setenv PATH /path/to/mySQL:${PATH}` at the top of your script. Good luck. – shellter Aug 02 '12 at 21:18
  • the name of my script is misleading. it says mysqlconnection.csh::command not found. It is NOT mysql command not found because when i type ./mysqlconnection.csh the script runs and connects me to the database. – rambokayambo Aug 02 '12 at 21:21
  • yes but your local PATH that is sourced from your .chsrc file is (likely) not being used by your Java program. If you're calling your script using the full path name, AND you've correctly spelled it, AND your getting the message 'command not found', its' almost certainly something inside the script that is producing the error message. sorry about inconsistent spelling of mysql in my orig. comment. I hope that has added to the confusion. Good luck. – shellter Aug 02 '12 at 21:51
  • i dont believe something inside the script is producing the error. When i go to the location of the script and type ./mysqlconnection.csh it works and the script connects to the db...so i dont think its the script – rambokayambo Aug 02 '12 at 22:08

0 Answers0