File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
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
Author

Executing Shell command in the same process

Srinivas Kothuri
Greenhorn

Joined: Feb 08, 2010
Posts: 16
Hi,

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
author
Sheriff

Joined: Sep 28, 2004
Posts: 18765
    
  40

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.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Executing Shell command in the same process