DmitryB
DmitryB

Reputation: 1179

Running external program

What's the difference between running programs using java and run it using the command line? In the first case it does not work, but in the second case it works fine.

Java:

try {
    Runtime runtime = Runtime.getRuntime();
    Process proc = runtime.exec("../../../my/prog \"//10.124.12.15/C:/output/*\" ../../../input/345 -N -A");
    DataInputStream bis = new DataInputStream(proc.getInputStream());
    int _byte;
    while ((_byte = bis.read()) != -1)
        System.out.print((char)_byte);
    proc.waitFor();
} catch (IOException ex) {
    ex.printStackTrace();
} catch (InterruptedException ex) {
    ex.printStackTrace();
}

AND command:

../../../my/prog "//10.124.12.15/C:/output/*" ../../../input/345 -N -A

Upvotes: 0

Views: 118

Answers (2)

DmitryB
DmitryB

Reputation: 1179

Thanks all, I solved my problem:

try {
    String cmd="/progs/my/prog //10.124.12.15/C:/output/* /temp/input/345 -N -A" 
    Runtime runtime = Runtime.getRuntime();
    Process proc = runtime.exec(
       new String[]{"/usr/bin/bash", "-c", cmd, "1>/dev/null 2>&1"});    
    proc.waitFor();
} catch (IOException ex) {
    ex.printStackTrace();
} catch (InterruptedException ex) {
    ex.printStackTrace();
}

Upvotes: 0

Mohammad Moghimi
Mohammad Moghimi

Reputation: 4696

Try using absolute path. Maybe that's your problem.

Upvotes: 2

Related Questions