Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2007

Tip: Looking for answers? Try searching our database.

Looking for Program Executor class in java

Thread view: 
Prafulla T - 19 Jan 2007 20:01 GMT
Hello
I am looking for class which will encapsulate a process(with no GUI)
and will execute the program
corresponding to that process.
What I mean is I am looking for some class which will allow me to
execute a.out programs ,same way we execute in Shell.
I am trying to implement it but got no success.
Steve W. Jackson - 19 Jan 2007 20:10 GMT
> Hello
> I am looking for class which will encapsulate a process(with no GUI)
[quoted text clipped - 3 lines]
> execute a.out programs ,same way we execute in Shell.
> I am trying to implement it but got no success.

Did you look at Runtime.exec?  Or at Java 5's new ProcessBuilder?
Signature

Steve W. Jackson
Montgomery, Alabama

Alex Hunsley - 19 Jan 2007 22:28 GMT
> Hello
> I am looking for class which will encapsulate a process(with no GUI)
[quoted text clipped - 3 lines]
> execute a.out programs ,same way we execute in Shell.
> I am trying to implement it but got no success.

What did you try so far? Give more details than just "got no success".
System.exec could be what you need, as the other replier said.
Prafulla T - 07 Feb 2007 17:53 GMT
> > Hello
> > I am looking for class which will encapsulate a process(with no GUI)
[quoted text clipped - 10 lines]
>
> - Show quoted text -

Do you know what system("any executable") function does in C?
It simply executes command passed to it.
No need to take any OutputStream and InputStream.
I want such a thing in Java.
I want to be able to execute a process and OutputStream should be
Stdout & InputStream should be stdin.
You know how to do it???
Gordon Beaton - 07 Feb 2007 18:09 GMT
> Do you know what system("any executable") function does in C? It
> simply executes command passed to it. No need to take any
> OutputStream and InputStream. I want such a thing in Java. I want to
> be able to execute a process and OutputStream should be Stdout &
> InputStream should be stdin.

Java's mechanisms for executing child processes (Runtime.exec() and
java.lang.ProcessBuilder) do not let the child share the same input
and output streams as the Java application itself.

The child's streams are always connected through streams available
through a Process object. As such, these mechanisms more closely
resemble p2open() (or popen()) than system().

/gordon

Signature

[ don't email me support questions or followups ]
g o r d o n  +  n e w s  @  b a l d e r 1 3 . s e

Chris Uppal - 07 Feb 2007 19:00 GMT
> Do you know what system("any executable") function does in C?
> It simply executes command passed to it.
> No need to take any OutputStream and InputStream.
> I want such a thing in Java.
> I want to be able to execute a process and OutputStream should be
> Stdout & InputStream should be stdin.

As far as I know (and I'd be very pleased to be shown I'm wrong) there is no
way
(short of using JNI) that you can execute a external program from Java and have
it inherit its stdin/stdout/stderr from the parent process.

The best I can think of is to attach threads to each of the external process's
streams which forward to/from the corresponding System.out/err/in.  And that,
unfortunately, is not quite the same...

   -- chris


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.