• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

r.exec("javac","source.java);

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for reading this

I have written a simple text editor to create .java source files.
I want to be able to launch the javac compiler from within this application.
I can call native processes as follows
Eg.
Runtime r=Runtime.getRuntime();
r.exec("notepad");
and although I can get javac.exe to run in a Dos screen I do not seem able to pass it the .java file I wish it to compile.
I have tried
r.exec("javac","source.java);
but this does not seem to work.
Any ideas?

 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the other thing I would be tempted todo is:
define them as a seperate String array and
pass them into the r.exec() method.
Also, did you check the
SecurityManager.checkExec(java.lang.String)
Let us know more details, so we could help.
regds.
- satya
 
simcel jones
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello satya
thanks for your help
i have tried the string array but this did not work either??
will let you know if i make any progress
thanks
simo
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try providing the complete file path, rather than just the name. E.g. "C:\projects\program1\source.java" rather then "source.java".
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello,
try this
r.exec("javac source.java");//give space and only as one string
if the source.java is in the same directory or give full path like
r.exec("javac C:\mydir\source.java");
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was able to get Acrobat to execute this way and to pass
it a PDF in the command line doing something like this:
> public class acrobatReader{
> public static void main(String args[])throws IOException{
> Runtime r=Runtime.getRuntime();
> Process p=null;
> String pdfName = "test.pdf";
>
> try
> {
> String s= ("c:\\adobe\\acrobat4\\AcroRd32.exe " + pdfName);
> p=r.exec(s);
> }
> catch(Exception e){
> System.out.println("error==="+e.getMessage());
> e.printStackTrace();
> }
> }
The main problem I have is that if I call another java program
instead of some C++ executable like this, then my DOS
window stays connected to that process...even if my executable
is run in another thread. If you have any thoughts on that,
I'd like to hear 'em.
-Mark
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There have been a few posts in the past about the persistent DOS window. The discussions usually end up focusing on executable JAR files or the use of javaw.exe. For your problem, I recommend the latter. It runs like java.exe but the dos window closes when the JVM starts.
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try taking the comma out of the parameter and putting both in double quotes like:
Runtime.getRuntime().exec("jar -tf whatever.jar > output.txt");
 
Screaming fools! It's nothing more than a tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic