Win a copy of Mastering Corda: Blockchain for Java Developers this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

Can I Call A Seperate Program Inside Another?

 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok So I Have two programs, One program to write to a new document a list of variable values I have captured. And another to do something similar with another set of values.

I realise that I can simply call two seperate programs within the command prompt window but is there a way by writing a method and stipulating a path (like a css regeference to html) where I can call the second program.

I'd rather do this than add the class from one program to the other and then fiddle around with it.
This may sound silly to some but is it possible?

regards S
 
Sheriff
Posts: 22054
113
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can load the class and call its static main method. If you know the class at compile time it's simply a matter of calling If you don't know the class at compile time you can use reflection to execute the main method:
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that this may not really be what you want to do.

Depending on how things are written and used it might be just as easy to pipe the output of one program (instead of writing it directly to a file as you do now) into the input of another. This is *much* more versatile than writing to a file, because you can still get the file output by redirecting to a file. So instead of:

$ foo outputFileName

you'd enter:

$ foo > outputFileName

This lets you do things like:

$ foo | bar > outputModifiedByBarFileName

I don't see any advantage of calling one program from within another: you've already introduced a dependency, so you might as well do it right and just have its classes on the classpath and do it all using normal Java, with the caveat that your code as it stands is not really set up for any sort of re-use or extensibility.
 
Oh the stink of it! Smell my tiny ad!
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic