Looking for Program Executor class in java

P

Prafulla T

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.
 
S

Steve W. Jackson

"Prafulla T said:
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.

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

Alex Hunsley

Prafulla said:
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.

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.
 
P

Prafulla T

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.



- Hide quoted text -

- 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???
 
G

Gordon Beaton

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
 
C

Chris Uppal

Prafulla said:
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
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top