2

Trying to write code to run cygwin commands from java code using processbuilder. not sure what's wrong. Please help me, Thank in Advanced!!

following code

import java.io.*;

public class test_6 {
    public static void main(String[] args) throws Exception {
        ProcessBuilder buildercmd = new ProcessBuilder(
            "cmd.exe", "/c", "cd \"D:\\csi\" && dir" +
                    "&& dir");

        ProcessBuilder buildercygwin = new ProcessBuilder(
                "D:/app/Cygwin/bin/bash", "-c", "cd /cygdrive/D/csi/ && dir" +
                        "&& ls -l");

        buildercygwin.redirectErrorStream(true);
        Process p = buildercygwin.start();
        BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
        String line;
        while (true) {
            line = r.readLine();
            if (line == null) { break; }
            System.out.println(line);
        }
    }
}

it worked using cmd as you see on my code but some reason its not working using cygwin.

following output i am getting:

/usr/bin/bash: dir: command not found

1 Answers1

1

try using the full path to dir => D:/app/Cygwin/bin/dir

cygwin has a dir.exe, for the windows version it is an internal commmand. source:

https://superuser.com/questions/229945/where-are-the-standard-windows-prompt-commands-files

Community
  • 1
  • 1
  • I tried that, 'D:/app/Cygwin/bin/dir' but still getting same error '/usr/bin/dir: cannot access cd /cygdrive/D/csi/ && dir&& ls -l: No such file or directory' Thank for your help.. – Jayraj Patel Jun 23 '15 at 11:43
  • Hi, that is a different error message: `usr/bin/dir: cannot access cd /cygdrive/D/csi/`, so your `dir` command is fine/found, it's another issue with your paths – codemonk113 Jun 23 '15 at 16:50