Solved

VI/Notepad from java and interact with it

Posted on 2014-11-03
3
260 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This video teaches viewers about errors in exception handling.

717 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