开发者

java.lang.UnixProcess inherently slow executing `find` on NTFS?

I was trying to get a list of files under a directory using:

val d = "..." // Path to a directory on a NTFS partition
val pb = new ProcessBuilder("find", d, "-type", "f", "-print")
pb.directory(new java.io.File(d))
val p = pb.start()
p.waitFor()
val listOf开发者_如何学PythonFiles = scala.io.Source.fromInputStream(p.getInputStream).getLines

However, the p.waitFor() is taking more than a minute to finish.

If I execute find . -type f -print in bash while on the directory, however, it takes less than a second to finish.

Therefore, is java.lang.UnixProcess inherently slow on a NTFS partition, or am I doing something wrong?

Using Scala 2.8.1, Java 1.6.0_24-b07 on a Ubuntu 10.10.


You should consume the stdout and stderr streams of the process because find might be writing to them and blocking.

Take a look at the post, When Runtime.exec() won't, for more information. They use a StreamGobbler to read the output streams so your process doesn't hang.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜