Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to run multiple processes at once, while still able to type commands to system.in

 
Unnar Björnsson
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an assignment that involves making a command provider through system.out and system.in. Im kinda stuck because my application needs to be able to open other application (notepad, cmd, etc.) and I have accomplished that but the application needs to be able to run multiple processes at once, thats where I get stuck because when I run a application like notepad my command provider which I feed commands in order to run applications, stops responding.

Basicly here�s how I do it:


So when I type: run notepad. A notepad runs with empty txt file, but if I type: run notepad c:\myDocument.txt it opens notepad and loads the given text file.

How do I run multiple instances of f.ex notepad? I�ve tried using threads but it ain�t quite working.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you show us your threading code that didn't work, please?
 
Unnar Björnsson
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here it goes:


I created an instance of Program every time the executeRun command is called.

 
Roy Ben Ami
Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Don't call the run method directly.

Call start() instead and it will work.

When you call run() directly it acts just like any other function. What you really need is to create a new thread and run it, and you use the start() method for that.
 
Unnar Björnsson
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I figured it out, I was referring to the array program that wasn�t in the run() methods scope so I got NullPointerException. Thanks for the help though.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic