?
Solved

VI/Notepad from java and interact with it

Posted on 2014-11-03
3
Medium Priority
?
277 Views
Last Modified: 2014-11-09
Hi there,
I have a console program built using the deadline clone, JLine and need to call a full editor from it to make editing easier.  The java program will have to call 'vi' or VIM or notepad on windows and allow the user to interact with it. Then when it is closed, the process would end and control return to the java console program.

Currently, most of the research I see is based around Runtime.exec and calling Process.waitfor for it to return.  
Now, this runs, but the terminal window is not showing vi and is blocking.

Has anyone called an external program from java and have it take control of the console like this?  I want to be able to do this from a prompt.  Assume 'prompt>' is my command line running jline.

prompt> edit

here I can capture the command edit from JLine and process it to call
    Process p = Runtime.getruntime().exec("vi blah.txt");

then I can call

   p.waitFor()

which should block until my vi session comes back.  And, while in vi, I can do all the normal things, before saving and coming back to my java console session.

 Now, my question is this, Does Runtime work in this situation? Can I control the terminal like this?  If not, I'm open to suggestions to something that will work.
0
Comment
Question by:BarryMcGillin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 40420176
I think it's going to be very difficult to pass control to a console editor (like basic vi) and then back to your app. A gui editor (like Notepad) would of course be easier
0
 
LVL 2

Accepted Solution

by:
BarryMcGillin earned 0 total points
ID: 40421267
Leave it long enough and you figure it out.  Redirecting the input and output sorted it out.  Simply put, this will do it.

    ProcessBuilder builder = new ProcessBuilder("/usr/bin/vim");
    Map<String, String> environ = builder.environment();
    builder.redirectInput(ProcessBuilder.Redirect.INHERIT);
    builder.redirectOutput(ProcessBuilder.Redirect.INHERIT);
    final Process process = builder.start();
    process.waitFor();
0
 
LVL 2

Author Closing Comment

by:BarryMcGillin
ID: 40431056
Didn't get a solution and ended up finding something that worked for me in javadoc released on 1.7 and 1.8
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
When there is a disconnect between the intentions of their creator and the recipient, when algorithms go awry, they can have disastrous consequences.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Progress
Suggested Courses
Course of the Month8 days, 23 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question