Categories

JAVA DATEBASE
Technology Network Community
Oracle Database
Fusion Middleware
Development Tools
Java
Desktop
Server & Storage Systems
Enterprise Management
Berkeley DB Family
Cloud Computing
Big Data
Business Intelligence
Architecture
Migration and Modernization
E-Business Suite
Siebel
PeopleSoft Enterprise
JD Edwards World
Industries
JD Edwards EnterpriseOne
User Productivity Kit Pro (UPK) and Tutor
Governance, Risk & Compliance (GRC)
Master Data Management (MDM)
Oracle CRM On Demand
On Demand: SaaS and Managed Applications
AutoVue Enterprise Visualization
Primavera
ATG
Agile PLM
Endeca Experience Management
Fusion Applications
Archived Forums

 



Tags

New To Java


Command line execution


Hi all,  I need to execute a command line program, which pauses in between for user to press enter key. I am displaying the result of the program in JTextArea. I need to press enter in JTextArea which resumes the program. Can anyone suggest a piece of code to do this.  Thanks in advance.

What exactly is the program supposed to do? "Command line" and "JTextArea" in the same question sounds a bit confusing.

When you exec a program, you get a java.lang.Process object.  From that object, you can get the input and output (and error) streams that would normally be tied to the console I/O if you executed the program from the console.  So if you want to do the equivalent of pressing enter...then you just send a newline to the process's input stream.  But you should also check to make sure that the program doesn't have an option that lets it run in non-interactive mode, so you wouldn't have to press enter.  Also read this:  http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

CROSS POSTED [http://forum.java.sun.com/thread.jspa?threadID=5295763]  Cross posting is rude.  db

But i need to press enter key from keyboard in JTextArea(GUI)

If you wish to continue in this thread then first go and mark the other thread as abandonned.

I m sorry for the cross posting. As i m new to the forum, i dint knew where can i get the answer to my question. I dont even konow how to delete this post.

You can't delete any post... what you can do is post a message in your other thread saying something like:    Thread anbandonned.  I crossposted this question to [this thread|http://forum.java.sun.com/thread.jspa?messageID=10251006] on the The New To Java Forum. I will continue to persue this question in my other thread. If you wish to respond then please follow the above link. I'd love to talk to you.  Sorry. I'm new here... I won't do it again.    Hint reply to this message and hit the quote button to see how to do links and HL's  Cheers. Keith.  Edited by: corlettk on 14/05/2008 10:31

poppy25 wrote: But i need to press enter key from keyboard in JTextArea(GUI)  You can press an enter key from the keyboard in a JTextArea, capturing it with the appropriate listener.  You can send a newline to the process by writing to its standard input stream, as I mentioned.  You can do those things separately, or you can tie them together by making the listener send the newline (or tell something else to send the newline).

Is it possible to make a comand line program which DOESN'T pause while user is inputting text to command line?

Actually, the command line program on terminal runs in following manner. The program executes while writing something on the terminal. Then the user needs to press Enter key to continue. And it executes further. Now my question is how do i make such kind of command line program execute from a java program while the result is written in JTextarea, and the user presses enter in the JTextarea( Jtaxtarea behaves like terminal in my GUI)  Edited by: poppy25 on May 14, 2008 10:02 PM

poppy25 wrote: Actually, the command line program on terminal runs in following manner. The program executes while writing something on the terminal. Then the user needs to press Enter key to continue. And it executes further. Now my question is how do i make such kind of command line program execute from a java program while the result is written in JTextarea, and the user presses enter in the JTextarea( Jtaxtarea behaves like terminal in my GUI)  Edited by: poppy25 on May 14, 2008 10:02 PM  Pretty much what I've already told you.  What part of it didn't you get?  You take the output and error streams from the Process, and make them write to the JTextArea.  You use text events on the JTextArea, and write them as input to the Process.  I see no point in going into more detail until you ask a specific question whose answer wouldn't be "read the documentation".

dovydas wrote: Is it possible to make a comand line program which DOESN'T pause while user is inputting text to command line?  It depends on what you mean by "command line program" and for that matter what you mean by "console", but the short answer is, yes, using Curses; Google for Curses (or CURSES I don't recall how it's supposed to look) and JCurses if you want to write it in Java.

If you are using a GUI why stuff about with the command line? Just provide another JTextArea or JTextField for the user to enter data.

How do i write input to a process?


Related Links

LinkedHashMap problem (Same key but different value)
A simple question
Python vs. Jython
Mortgage Calculator Help
Call method every 5 minutes
Quantum Processor (8 GflopS) trade release announced
i want a Java program that confirms the first three letters are alpha
Quick query about loop statements
Using methods and classes...
Can someone show me what i'm wrong?
Java Utility- Populate Access Database using several .txt files
Error 2753 regutils.dll
Can't convert int into String
How much should coding conventons be applied?
Reading From File And Sum of Last 2 Integers
Help with assignment