Forums Register Login

Execute an application from java and interact with it.

+Pie Number of slices to send: Send
Hello All,

I trying to execute an application using java code "Process p = Runtime.getRuntime().exec(cmd);" but this does'nt allow me to interact with this application. Is there any way , we can read the output of executed application and again pass on some input parameters to that application based on it output in the first step . Please let me know if something is not clear.

Thanks,
A
+Pie Number of slices to send: Send
Abhiram,
Welcome to CodeRanch!

This JavaWorld article doesn't answer your question,b ut it is a great read about Runtime.exec so I recommend it anyway. I don't think you can do what you are asking. Runtime.exec isn't meant to be interactive. It's meant to kick off a process and get output back.

Did you write the Java program that you want to call? Do you know who did?
1
+Pie Number of slices to send: Send
Absolutely definitely read the article Jeanne linked to. It is a must read for anyone using Runtime.exec.

To answer your question it is possible to have a simple interaction with an application you have launched through Runitme.exec (or better still via java.lang.ProcessBuilder) provided that the interaction can be achieved via input/output streams ie the application must take input from and write its output to the command line.
+Pie Number of slices to send: Send
Look at the Process class. It is meant to interact with command line applications only not with GUI ones.

Interacting with GUI ones is quite more tricky and usually involves a frame buffer. I have never done this with java.
+Pie Number of slices to send: Send
Interacting with GUIs is even more tricky since GUIs are usually not threadȁsafe.
Just let me do the talking. Ahem ... so ... you see ... we have this tiny ad...
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1004 times.
Similar Threads
Running a .bat/ .cmd file from Java
Help for getting output of Runtime.getRuntime().exec()
java calling pearl scripts
How i execute cmd.exe via GWT
getRuntime().exec() issue
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 03:00:03.