我有一个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