File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Executing Shell command in the same process Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Executing Shell command in the same process" Watch "Executing Shell command in the same process" New topic

Executing Shell command in the same process

Srinivas Kothuri

Joined: Feb 08, 2010
Posts: 17

I want to run a shell command in the context of the current process in Java.
The way I know is using Runtime.getRuntime().exec() which will create a different process.
Actually I want to launching a browser in the same context of my java application.

Kindly tell me some work around for this.

Thank you in advance . . ..
Henry Wong

Joined: Sep 28, 2004
Posts: 20353

None of the current variations of Unix or Windows allow multiple processes to share the same virtual address space. This is obviously done to protect the processes from each other. So... no. Java can't do that.

However, if you want to run two java programs, you can kinda simulate it by writing / running a wrapper that calls the main() method of the two classes.... but in that case, you have to be real careful that the two java programs don't step on each other. The OS don't know that they are two processes, and hence, doesn't provide any protection.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
I agree. Here's the link:
subject: Executing Shell command in the same process
It's not a secret anymore!