Solved

VI/Notepad from java and interact with it

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
This is an explanation of a simple data model to help parse a JSON feed
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This video teaches viewers about errors in exception handling.

746 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now