• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Calling main method of one program from another program

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello to all,

I have one program which uses command line arguments for doing particular work. But when I am calling the main function from another program with appropriate arguments into string array, it does not work as it is working and giving output from the command line.

I have also tried "Runtime.exec()" method to call the class having main method, but results none.

Is there another way to perform the this opration?

Thanks in advance.
 
Marshal
Posts: 79402
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't understand the problem. Do you have all your classes in the same classpath? How are you invoking main() or Runtime.exec()?

Please supply more details and don't simply say "doesn't work".

Too difficult a question for "beginning". Moving thread.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rajshkhr Pandey,
Do you mean in following example, when you run Test2.main() it is not printing anything?


It works for me
 
Campbell Ritchie
Marshal
Posts: 79402
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

That is probably not what the question is about, I am afraid, since that will obviously work readily.
 
Chandrakant Talele
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oops , yes I interpreted the problem incorrectly, my apologies
Here is the sample program that will work. I hope I am correct this time.
I am running it in eclipse and "bin" is where my .class files are.



Thanks Campbell Ritchie for the welcome
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Probably all problems that can occur using Runtime.exec are explained in this article.

If you can alter the code for both applications, the easiest would probably be to add an appropriate constructor to the app being called through which you can pass the parameters, and then to instantiate (and run) it directly.
reply
    Bookmark Topic Watch Topic
  • New Topic