Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Spawning processes from Java in Native environment

1 view
Skip to first unread message

pidarah

unread,
Feb 12, 2001, 5:34:05 PM2/12/01
to
Hello

How can we create batch file in a Java program
which can execute a batch file in wondows 2000. I have written
this code but
its causing java.io.createProcess exception.

Is writing a SecurityManager policy which over
comes all the restrictions is a godd wat of doing this?? ( Anyway
I dont need any
kind of security at all.) Or anyone has any
suggestions??

Thanks
rahul

Joseph Millar

unread,
Feb 12, 2001, 6:41:36 PM2/12/01
to

By default, a Java application run using the standard tools
has no security restrictions. If you are running in this
kind of environment, then there is likely some problem with
your code.

If you're running in a secured environment, than you don't
get to pick what you can and can't do, that's up to whoever
setup the environment and you must play by their rules.
Many times there are ways to authorize code in these
environments, but that's going to be on a case by case basis.

java.io.createProcess exception? What's that? Perhaps you
should post the real stack trace and code sample and we can
take a look?

--Joe
________________________________________________________________
Joseph A. Millar <jmi...@mediaone.net>
"Very funny, Scotty! Now beam down my clothes!" - James T. Kirk

pidarah

unread,
Feb 13, 2001, 8:18:15 PM2/13/01
to
Hello

Thanks for the reply.

The stack is

(where Run is my batch file name)


java.io.IOException: CreateProcess: Run error=2
at java.lang.Win32Process.create(Native Method)
at java.lang.Win32Process.<init>(Unknown Source)
at java.lang.Runtime.execInternal(Native Method)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at LoadAverageReader.<init>(LoadAverageReader.java:17)
at LoadAverageReader.main(LoadAverageReader.java:97)

My basic doubt is how can we create mobile agents using Java, ie
which can go to a any predecided machine, where a code is being
run as anchor and got executed and send the results back

Thanks
rahul

-rahul

Heinz Huber

unread,
Feb 14, 2001, 3:16:47 AM2/14/01
to

pidarah wrote:
>
> The stack is
>
> (where Run is my batch file name)
>
> java.io.IOException: CreateProcess: Run error=2
> at java.lang.Win32Process.create(Native Method)
> at java.lang.Win32Process.<init>(Unknown Source)
> at java.lang.Runtime.execInternal(Native Method)
> at java.lang.Runtime.exec(Unknown Source)
> at java.lang.Runtime.exec(Unknown Source)
> at java.lang.Runtime.exec(Unknown Source)
> at java.lang.Runtime.exec(Unknown Source)
> at LoadAverageReader.<init>(LoadAverageReader.java:17)
> at LoadAverageReader.main(LoadAverageReader.java:97)

[...]

Error 2 means: (from WINERROR.H)
//
// MessageId: ERROR_FILE_NOT_FOUND
//
// MessageText:
//
// The system cannot find the file specified.
//
#define ERROR_FILE_NOT_FOUND 2L

Could you post the code you use?

hth,
Heinz

Roedy Green

unread,
Feb 14, 2001, 8:47:18 PM2/14/01
to
sOn Mon, 12 Feb 2001 14:34:05 -0800, pidarah
<pidarah...@sun.partner.remarq.com.invalid> wrote or quoted :

>
> How can we create batch file in a Java program
>which can execute a batch file in wondows 2000. I have written
>this code but
> its causing java.io.createProcess exception.

see exec in the Java glossary.

--

Please consult the JAVA GLOSSARY for almost any
Java-related question.
If the answer is not there, COMPLAIN!
See http://mindprod.com/jgloss.html
or http://209.153.246.39/jgloss.html

Answers to the five most Frequently Asked Questions:

1) for conversion problems, see "conversion". .
2) for I/O problems, see the "File I/O Amanuensis" and "File".
3) if you want to create a *.exe, see "native compiler".
4) if you are new to Java, see "getting started".
5) to spawn an external program see "exec".
--
Roedy Green, Canadian Mind Products
Custom computer programming since 1963

Ron Kracht

unread,
Feb 14, 2001, 10:36:03 PM2/14/01
to
pidarah <pidarah...@sun.partner.remarq.com.invalid> wrote in
<000000ea...@usw-ex0108-192.remarq.com>:

>Hello
>
> How can we create batch file in a Java program
>which can execute a batch file in wondows 2000. I have written
>this code but
> its causing java.io.createProcess exception.
>

I don't believe that it is related to this particular problem but one of
the things that you will have to watch out for with Win2k and also with NT
is that some operations are very sensitive to the system environment
variables. Since the exec'd process gets its environment from the parent,
and since a Java application gets essentially no environment variables from
the JVM you must explicitly create and pass an environment to the chid
process which recreates the necessary system environment variables.

I have run into certain system operations (connecting to a socket for one)
in child processes which would not work without SystemDrive and SystemRoot
being set properly in the environment. Normally this is not a concern since
the OS does this for you automatically but it is a concern in child
processes of a Java application.

Ron Kracht

0 new messages