0

I have to implement javap -verbose from within a java program, the directory named folder has multiple classes and i want to use this javap -verbose on all of them so i do,

Process p = Runtime.getRuntime().exec("javap -verbose folder/*");

in my java program but it does not work(Program compiles and runs but no output is obtained), However when i do

Process p = Runtime.getRuntime().exec("javap -verbose folder/java_1.class");

it runs(and output is obtained). Also if I do

javap -verbose folder/*

on the command line it works. I am using latest version of Ubuntu. How can i apply javap on all the files of a directory. Note: folder has no sub-directory.

F_society
  • 1
  • 1
  • it seems you need to recurse all the files to be passed to `javap` – Bagus Tesa Mar 16 '18 at 00:59
  • @BagusTesa how can I do that, and why is it that using * works in command line but not from within java file – F_society Mar 16 '18 at 01:09
  • You have to implement this why? Very strange requirement. – user207421 Mar 16 '18 at 01:48
  • It works well on my environment. –  Mar 16 '18 at 01:58
  • @EJP I have to write a java program to analyze the number of constant pool in the classes (from n classes kept in a directory) – F_society Mar 16 '18 at 02:02
  • @saka1029 it runs on mine as well but no output is generated, the program runs and then just ends, I used inputstream to catch the output and the output is nothing. – F_society Mar 16 '18 at 02:04
  • 1
    Mostly dupe https://stackoverflow.com/questions/31776546/why-does-runtime-execstring-work-for-some-but-not-all-commands -- `Runtime.exec` is not a shell, so you must either run a shell to expand the pattern (and then execute javap), or expand the pattern yourself. (PS: this actually works only if 'folder' is actually a package of classes. Java _sometimes_ uses directory=folder structure for package structure, but there are lots of directories or folders which aren't packages, and lots of files that aren't classes, and this won't work in those cases.) – dave_thompson_085 Mar 16 '18 at 02:19

0 Answers0