Please help with thread problem

S

Sandra

Hi, I need to execute a program from an other and I use this method:


public class P1 {
public static void main(String arg[]) {
new Thread(){
public void run() {
P2.main(new String[]{});}
}.start();
}

}

This works.
The problem is when program P1 is in C:\\dir1 and program P2 is in
C:\\dir2

The code

public class P1 {
public static void main(String arg[]) {
new Thread(){
public void run() {
C:\\dir2\P2.main(new String[]{});}
}.start();
}

}

doesn't work.
Maybe the problem are the '\\' characters?

How could I solve this problem?

Second problem: I need to execute a program from an other, but the
program to execute is in an other computer, networked to the first
one.
Let the program P2 be in computer at address 192.45.68.100
Now, I'm able for example to work on a database on an other computer,
using for example a code like


Connection c = DriverManager.getConnection("jdbc:mysql://192.45.68.100/recipeDB");

but I cannot figure out how to port this in my
program-to-open-an-other-program.

Please help!

Thank you very much

Sandra
 
G

Gordon Beaton

Hi, I need to execute a program from an other and I use this method:
[...]

The code

public class P1 {
public static void main(String arg[]) {
new Thread(){
public void run() {
C:\\dir2\P2.main(new String[]{});}
}.start();
}

}

doesn't work.
Maybe the problem are the '\\' characters?

You are confusing the concepts of "classname" and "filename". Your
first example works because P2 is a classname, as it should be. Your
last example fails because C:\\dir2\P2 is not a classname.

The solution is to make sure the relevant classes can be found in the
classpath, either by setting an environment variable or providing a
classpath argument to the JVM when you start the application. Then you
can continue to use the first example.
Second problem: I need to execute a program from an other, but the
program to execute is in an other computer, networked to the first
one.

You need help from the remote computer. It needs to provide some kind
of remote execution server such as rshd, sshd or such, or one you've
written yourself, maybe using Java RMI. Once that's in place your
application can request that the server execute the code on your
behalf. Exactly how you do that depends on which method you've chosen.

What you are asking is basically how to remotely control execution of
code on the other computer, so there are important security issues to
be considered before you open a service for executing arbitrary
commands.

/gordon
 
A

Andrew Thompson

On 5 Oct 2004 14:52:04 +0200, Gordon Beaton wrote:

(Sandra)
You need help from the remote computer. It needs to provide some kind
of remote execution server such as rshd, sshd or such, or one you've
written yourself, maybe using Java RMI.

....hmmm. I first read that as the OP wanting to import a class
from a networked machine to run locally. But your interpretation
seems to fit better.

To the OP. Could you clarify where you want the networked class
to run - server or client?

Also to the OP. Note that it is not generally a good idea
to cross-post to these two *very* different groups. I recommend
you stick to c.l.j.help until you are familiar enough with each
group to decide which group is better for a particular question.

[ Follow-Ups set to c.l.j.help only. ]

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.lensescapes.com/ Images that escape the mundane
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,128
Latest member
ElwoodPhil
Top