2016-10-17 11 views
-1

"ls * .xml"を呼び出すプロセスを作成しようとしています。Javaプロセスの作成

このコードは、[OK]を動作します:

Process p=Runtime.getRuntime().exec("ls build.xml"); 
build.xml 

このコードが間違っている:

Process p=Runtime.getRuntime().exec("ls *.xml"); 
// this is the output 
Cannot run program "ls *.xml": error=2, No such file or directory 

任意のアイデア?

+1

を: 'Runtime.getRuntime()の幹部({「LS」、 "* .xml"})); –

+0

[パス内のチルダを使用したbashスクリプトの実行]の可能な複製(http://stackoverflow.com/questions/15273524/executing-bash-script-with-tilde-in-path) –

+1

注意:execを実行すると、 '*'や '>'のようなものを理解できるシェルが実行されていません。 –

答えて

1

これは、ワイルドカードの展開がlsコマンドではなく、Bashシェルによって行われるためです。

あなたがしたいすべてがFiles.newDirectoryStream使用し、リストファイルの場合:あなたは幹部の配列形式を使用する場合、何が起こるか

Files.newDirectoryStream(Paths.get(".")), p -> p.toString().endsWith(".xml")).forEach(System.out::println) 
関連する問題