osx - OS X command line application cannot find directory while called from Java -


if run in terminal works fine:

lsof -f n +d /some/directory 

but when run same thing java not:

                    process lsof = new processbuilder("lsof", "-f", "n", "+d", "'/some/directory'").start();                     lsof.waitfor();                      if (lsof.exitvalue() != 0) {                         bufferedreader reader = null;                         try {                             reader = new bufferedreader(new inputstreamreader(lsof.geterrorstream()));                             string line = null;                             stringbuffer sb = new stringbuffer();                             while ((line = reader.readline()) != null) {                                 sb.append(line);                                 sb.append("\n");                             }                              log.warning("stdout:\n" + sb.tostring());                         } {                             if (reader != null) {                                 reader.close();                             }                         }                     } 

when called java returns:

stdout:   lsof: warning: can't stat('/some/directory'): no such file or directory lsof 4.85  latest revision: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/  latest faq: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/faq  latest man page: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/lsof_man  usage: [-?abhlnnooprtuvv] [+|-c c] [+|-d s] [+d d] [+|-f[cgg]]  [-f [f]] [-g [s]] [-i [i]] [+|-l [l]] [+|-m] [-o [o]] [-p s] [+|-r [t]] [-s [p:s]] [-s [t]] [-t [t]] [-u s] [+|-w] [-x [fl]] [--] [names] use ``-h'' option more information. 

can explain why?

new processbuilder("lsof", "-f", "n", "+d", "'/some/directory'")                                              ^               ^ 

remove single quotes surrounding /some/directory. being passed through lsof program , being interpreted part of pathname.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -