How to get 2nd app to write to 1st app "System.In"?

Hey, I am trying to build a program that will control another program. It will do this by reading the output of the program and then sending it information as if a user had typed it in.
The problem is that the 2nd app (referred from here on as the "CONTROLLER"), when run, hangs on the spot where the 1st app (referred from here on as the "HOST"), is waiting for "System.in" input.
So the CONTROLLER will read the first line, display it, but then where it is supposed to wait for the user to type something in and write it to the HOST (which is using System.in for input), it hangs up. Because I have the .close() method inside my methods, it now at least closes the app instead of freezing.
I've read http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html "When Runtime.exec() won't", and it doesn't really address my problem except to say "Thus, to circumvent the second pitfall -- hanging forever in Runtime.exec() -- if the program you launch produces output or expects input, ensure that you process the input and output streams."
Which is fine, but I don't know how to handle the HOST using System.in waiting for input in my CONTROLLER app. Anyone got a method I can use for this? Here is the code.
HOST:
import java.io.*;
public class myTest4 {
     public myTest4() {
          InputStreamReader inText = new InputStreamReader(System.in);
          BufferedReader buffText = new BufferedReader(inText);
          try {
               System.out.print("Enter Customer Number:  ");
               String firstIn = buffText.readLine();
               int newvalue = Integer.parseInt(firstIn);
               char char1 = firstIn.charAt(0);
               System.out.println("Customer number entered: " + firstIn);
                    if (char1 == '1') {
                         System.out.print("Enter Comment:  ");
                         String comment = buffText.readLine();
                         System.out.println("You entered - " + comment);
                         System.out.println("Press ENTER to exit:");
                         System.in.read(new byte[10]);
                         System.exit(0);
                    else {
                         System.out.println("Press ENTER to exit:");
                         System.in.read(new byte[10]);
                         System.exit(0);
          catch(IOException err) {
              System.out.println("Error reading line");
          catch(NumberFormatException err) {
               System.out.println("Error Converting Number");
     public static void main(String[] args) {
               myTest4 free = new myTest4();
     }CONTROLLER:
import java.io.*;
class LegacyProviderTest {
     protected Process theProcess;
     public void startSession(String command)
          throws IOException, SecurityException, NullPointerException,
          IllegalArgumentException, InterruptedException
          theProcess = Runtime.getRuntime().exec(command);
     public String readLines()
     throws IOException
          char[] theLine = new char[5000];
          int index = 0;
          BufferedReader is = new BufferedReader(new InputStreamReader(theProcess.getInputStream()));
          while (index < theLine.length)     {
               int theCharacter = is.read();
               if (Character.isISOControl((char)theCharacter)) {
                    break;
               else {
                    theLine[index++] = (char)theCharacter;
          is.close();
          String theResult = new String(theLine);
          return theResult;
     public void writeLines(String line)
     throws IOException
          char[] theChars = new char[line.length()];
          BufferedWriter os = new BufferedWriter(new OutputStreamWriter(theProcess.getOutputStream()));
          for (int i=0; i < line.length(); i++) {
               theChars[i] = line.charAt(i);
          os.write(theChars);
          os.close();
     public static void main(String args[]) {
          String input;
          LegacyProviderTest legacy = new LegacyProviderTest();
          try {
               legacy.startSession("java mostSimple");
               input = legacy.readLines();
               System.out.println("Read input: " + input);
               if (!input.equals("Enter Customer Number:  ")) {
                    System.out.println("Invalid response: " + input);
                    System.exit(1);
               legacy.writeLines("12345");
               input = legacy.readLines();
               System.out.println("Read input: " + input);
               if (!input.equals("Enter comment:  ")) {
                    System.out.println("Invalid response: " + input);
                    System.exit(1);
               legacy.writeLines("hi there");
               legacy.writeLines("");
               System.out.println("Yahoo!!");
          catch (Exception e)     {
               System.out.println("Got exception " + e);
               System.exit(1);

>
Process p = Runtime.getRuntime().exec(my_cmd);
InputStream inputStream = p.getInputStream();
If you notice, I have the InputStream already initialized and then buffered, and the process is initializing correctly (to the point where it asks for System.in input).

Similar Messages

  • TS3991 iWork doesn't seem to recognize that I already have the pages, keynote, and numbers apps so I can't use iCloud to sync my documents.  How to get my apps recognized?

    iWork doesn't seem to recognize that I already have the pages, keynote, and numbers apps so I can't use iCloud to sync my documents.  How to get my apps recognized?

    Do you have both the OS X and iOS versions of each of them?

  • Can someone tell me how to get my apps that are on my ipad to appear on my TV using Apple Tv

    Can someone tell me how to get my apps that are on my IPad to be viewed on my Apple TV?

    Welcome to the Apple Community Coachcad.
    Basic AirPlay: Assuming both devices are on the same network and that AirPlay is not turned off on the Apple TV, then simply tap on the screen when you are watching content you wish to stream to your Apple TV, then tap the airplay icon that appears in the control bar, choose the Apple TV from the menu that appears.
    Mirroring: When displaying the content you wish to mirror on the iPad 2 (or better), iPad Mini, iPhone 4S (or better), swipe from the bottom of the screen, tap the AirPlay icon and choose your Apple TV from the list of devices (iOS 7 or better) or double tap the home button (quickly) and swipe the bottom row of apps to the right to reveal the playback controls, tap the AirPlay icon and select your Apple TV from the list of available devices (pre-iOS7)

  • How to get 2nd line in smartforms using template

    how to get 2nd line in smartforms main window using template. i have also defined loop .

    if possible can you try with the TABLES..
    Put one TABLE in your MAIN window
    create table lines as per your requirment...consider all lines like 6 for header, 1 for main, 1 for total
    Now, you will find three section under the tables: header, main, footer...
    in header section, create a table line, assign one of the proper lines from the line types.. repeat for your all lines.
    in main section, you can access your data form the loop.
    the footer secion will be called, just after the main will be finished.
    Regards,
    Naimesh Patel

  • I just bought my iPad air and I would like to know how to get the App Store on it

    I just bought my iPad air and I would like to know how to get the App Store on it?

    It is included.

  • TS1702 When I try to update two certain apps in the App Store, I get a message that says 'cannot connect to iTunes store'. Any idea how to get these apps to update?

    When I try to update two certain apps in the App Store, I get a message that says 'cannot connect to iTunes store'. Any idea how to get these apps to update?

    Check that the apps are still available in the store

  • My Itunes account is on my dad's user. I downloaded Itunes on my user, and I am wondering how to get the apps I downloaded on my dad's user, on mine? Sorry if the question is confusing.

    Our computer has users that you click to log on. My itunes thingy is on my Dad's and I downloaded Itunes on my user, and i am wondering how to get the apps I downloaded on my  dad's itunes, to mine. Thanks for any help.

    iPads sync to 1 computer only.
    All media and apps are tied to the Apple ID that purchased them.
    Without your relatives ID and password, you cannot update any of the Apps.
    I am pretty certain he is also violating Apples terms of service by giving you the apps.

  • I accidentally deleted all my apps and music. I can re-download the music but don't know how to get the apps back without buying them again. Any thoughts?

    I accidentally deleted all my apps and music. I can re-download the music but don't know how to get the apps back without buying them again. Any thoughts?

    Just follow this:
    Downloading past purchases from the App Store, iBookstore, and iTunes Store

  • How to get online apps to work with the Verizon DSL modem firewall set at "Medium" level, not "Low?"

    How to get online apps to work with the Verizon DSL modem firewall set at “Medium” level? Xbox 360 Live, FTP, and the Windows sntp Time checker native to Windows XP WON’T WORK unless the Verizon firewall is first reset down to “Low.” Then all works well, but I then risk low firewall protection. Setup: · Westell 6100 DSL modem (Software Version: VER:4.04.03.00 Transceiver Revision: 7.2.3.0 Model Name: C90-610015-06), · D-Link DIR-655 wireless router (Hardware Version: A3, Firmware Version: 1.21), For Xbox 360 Live the “canned” port forwarding rule for provided in Verizon’s drop-down list for the Westell 6100 modem forwards ports 88 and 3074 for both TCP and UDP. This does not meet Microsoft’s forwarding recommendations for Xbox 360 Live stated at http://support.microsoft.com/kb/908874. Instead, for the Verizon modem (Westell) I made a new port forwarding rule to comply with those Microsoft instructions. It forwards ports 53, 80 and 3074 for TCP and ports 53, 88 and 3074 for UDP. These same ports are also forwarded in the D-Link router configuration. For FTP, port 21 is also forwarded for TCP and UDP in both modem and router. But they don’t work until I first cripple the Verizon firewall down to “Low.” How to get them to work with the Verizon firewall up to Medium?

    While I do not know the answer to your question, BUT since you have this modem and another router - you could just follow.
    http://www.dslreports.com/faq/13600
    ^^
    If you are the original poster (OP) and your issue is solved, please remember to click the "Solution?" button so that others can more easily find it. If anyone has been helpful to you, please show your appreciation by clicking the "Kudos" button.

  • How to I retrieve my purchased apps? I had my Iphone stolen in FEB, then in July my PC crashed. I just got a new Iphone but I dont know how to get the apps.

    How to I retrieve my purchased apps? I had my Iphone stolen in FEB, then in July my PC crashed. I just got a new Iphone but I dont know how to get the apps.

    Open itunes store, click Purchased under Quick links.
    Where is your backup copy of your computer?  You can use that as well.

  • How to get the size of physical memory by using system call ?

    how to get the size of physical memory by using system call ?What system call can be used for me to get the size of physical memor? thanks.

    %vmstat 3
    procs memory page disk faults cpu
    r b w swap free re mf pi po fr de sr s0 -- -- -- in sy cs us sy id
    0 0 0 3025816 994456 4 19 6 0 0 0 0 8 0 0 0 459 253 139 1 1 99
    0 0 0 2864688 777408 0 2 0 0 0 0 0 3 0 0 0 428 134 175 0 1 99
    0 0 0 2864688 777408 0 0 0 0 0 0 0 7 0 0 0 448 112 166 0 0 100
    one interesting observation about vmstat I found out is (mostly on Solaris)
    the first line of information always off chart, so I usually do a few interval to get constant result.
    if you use linux
    just
    cat /proc/meminfo

  • How to get list of drives present in local file system?

    Hi all,
    I want to show all drives and their contents using JTree.
    Does anybody know how to get list of drives present in local file system?

    Thank you!
    I have new question.
    I want to disply size and file type. Can you give ur suggestion in order to do that?
    I want to provide following using JTree
    + root <Dir> 50KB
    - file1 <txt> 10KB
    - file2 <bmp> 20KB
    + root2 <Dir> 200KB
    -file1 <jpeg> 50KB
    Is this possible?
    Plz reply..........
    bye

  • Hi!! I would like to know how to get my apps back. I got a new Iphone but my apps are in my pc and I do not know how to do it.

    Hi
    Can somebody helme to get my apps back?....
    I got another Iphone and my apps are in my PC, I already sincroniced but nothing happend..
    Thank you from San José del Cabo México

    Normally when you connect a new iPhone to your computer iTunes will recognize it as a new iPhone and ask you how would you like to set it up.  If you didn't get that screen then you may have used the iPhone prior.  If it didn't  then try deleting all data then connect the iPhone 4 to the computer and it should go to the iPhone setup screen where it will give you the opportunity to setup your iPhone as a new device (the name of your old iPhone should be in the name box).  If that don't happen then do this, keep your iPhone connected to the computer, launch iTunes then click on the iPhone icon in the left window then click on the app tab on the main window make sure all of the app have a check in the check box, also check all of your other tabs then re-sync. 

  • How To Get iWork Apps Free on iPad 4 Purchased in June 2013?

    Since I've got my new 13" MBPr in June 2014, the iWork apps are apparently preinstalled, my question is, can I get the iWork apps free on my iPad 4 purchased in June 2013? On Apple Store on my iPad 4, the iWork apps show a price tag of $9.99 each. Any idea how to get those iWork apps free on my iPad 4 using same Apple ID?

    iWorks apps for Mac and iWorks apps for iOS are different products, the apps only work on the appropriate operating system. They are therefore priced and sold separately.

  • IPhone & iTunes both had to be restored - how to get music & apps back?

    My iPhone and computer both crashed on the same day and I had to restore both. I lost all of my apps & music and there is no back up. Is there any way to get my apps & music back without purchasing everything again? iTunes clearly has a record of my purchases, so I would think there's some way to do this, but I just don't know how.
    Any help?

    Log into the iTunes Store with the same account you initially used, click the Buy button for each application again, and confirm you want to redownload it for free. For the music, click here and fill out the form.
    (45165)

Maybe you are looking for

  • I can no longer access my Time Capsule disk

    After upgrading to SL, I can't connect to the disk in my Time Capsule. It shows up in the Shared part of the Finder sidebar as usual, but clicking on it generates a gray bar that says "Connection Failed." On the right-hand side of this bar is a "Conn

  • TS3899 I can't see messages all of a sudden in my inbox when I connect via gmail but ok from message icon in my ipad

    Hi I have a problem. I was happily deleting and moving some emails from my Inbox on my ipad when all of a sudden, the messages just disappeared!!! When I tried to get to that page again, the address reads"mail.google.com/mail/mu/mp/12#tl/Inbox. So fr

  • The horizontal scroll bar appears in the middle on Safari.

    Hello. I have a problem of Ipad mini A few user has the same prolem like me T.T when I checked other users is using Ipad mini or related Ipad series on web. and I could not find solution for it, The probelm is : the horizontal scroll bar position is

  • Can i change operating language

    Hi, I but a PRS-T2/BC for my father and i will like to change the operating language to romanian. It is posible?

  • Using And Managing Eclipse

    How do people manage Eclipse? I have read the wiki and I find that installing plugins running as root is a pain because java isn't setup for the root user. If I install plugins as me through the IDE itself then they are blown away when Eclipse upgrad