It's all about Stream...

Hi' this is really makes me feel so upset. Why every time i try to execute WindowsExec file.
There's no error in code but the output not correctly.
WindowsExec.java :
public class WindowsExec
     response std_out,std_err;
     DataOutputStream doStream;
     outputer std_in;
     public WindowsExec()
          try
               String[] cmd = new String[]{"cmd.exe","/C","java","maintest"};
            Runtime rt = Runtime.getRuntime();
               Process proc = rt.exec(cmd);
               std_out = new response(proc.getInputStream(),System.out);          
               std_err = new response(proc.getErrorStream(),System.err);
               doStream = new DataOutputStream(proc.getOutputStream());
               std_in = new outputer(doStream);
               std_out.start();
               std_err.start();     
               std_in.start();
               int exitVal = proc.waitFor();
            System.out.println("ExitValue: " + exitVal);
               proc.destroy();
               doStream.close();     
          catch (Throwable t)
             t.printStackTrace();
    public static void main(String args[])
          new WindowsExec();
outputer.java :
class outputer extends Thread
     OutputStream write;
     BufferedReader bfr;
     public outputer(OutputStream write)
          try
               this.write = write;
          catch(Exception e)
               e.printStackTrace();
     public void run()
          try
               bfr = new BufferedReader(new InputStreamReader(System.in));
               String input = null;
               input = bfr.readLine();
               write.write(input.getBytes());     
               write.flush();
               write.close();
               bfr.close();          
          catch(Exception e)
               e.printStackTrace();
response.java
class response extends Thread
     InputStream is;
     PrintStream type;
     public response(InputStream is, PrintStream type)
          this.is = is;
          this.type = type;
     public void run()
          try
               InputStreamReader isr = new InputStreamReader(is);
                      BufferedReader br = new BufferedReader(isr);
                      String line = null;
                      while ( (line = br.readLine()) != null)
                                      System.out.println(line);   
               br.close();
               isr.close();
               is.close();
          catch (Exception ioe)
                        ioe.printStackTrace(); 
maintest.java
public class maintest
     public maintest()
          try
               BufferedReader bfr = new BufferedReader(new InputStreamReader(System.in));
               System.out.print("Insert : ");
               String getWord = bfr.readLine();
               System.out.println(getWord);
          catch(Exception e)
               e.printStackTrace();
     public static void main(String[] args)
          new maintest();
}This is the illustration :
1. Execute WindowsExec
2. Maintest executed from WindowsExec. (see WindowsExec source).
3. Display the output.
The output should be like this : (see maintest source to check)
1. Print Insert : and wait input from user.
2. User write some input and press enter.
3. Read input from user and display it.
4. Program terminate.
But what i got, the output are like this : (this is not correctly)
1. Wait input from user. (see maintest source,the firstline should be print "Insert :",not waiting some input).
2. User write some input and press enter
3. print Insert : and read input from user and display it.
4. Program terminate.
Why the output become like that? (Conversation between WindowsExec and maintest not correctly).
Insert : should appear in the first line of the output.
How to get the right conversation between WindowsExec and maintest?
I hope my question easy to understand.
Thanks....

i still got the same output. Before you set the
classpath in linux.,did my WindowsExec give the right
output?
Of course not! That is why I had to set the classpath so that java could find the maintest class.
Have you tried the simplistic approach String[] cmd = {"java",  "maintest"};
String[] env = {"CLASSPATH=" + System.getProperty("java.class.path")};
Process proc = Runtime.getRuntime().exec(cmd,env);of course, this assumes that your jdk bin directory is on the PATH (not CLASSPATH) so that java --version should run. You could start with something simple like
String[] cmd = {"java",  "-version"};
String[] env = {"CLASSPATH=" + System.getProperty("java.class.path")};
Process proc = Runtime.getRuntime().exec(cmd,env);just to prove you are picking up java!
To make sure we are talking the same language -public class WindowsExec
    response std_out,std_err;
    DataOutputStream doStream;
    outputer std_in;
    public WindowsExec()
        try
            //String[] cmd = {"sh","-c","java -classpath " + System.getProperty("java.class.path") + " me.sabre150.research.scratch.maintest"};
            String[] cmd = {"sh","-c","java me.sabre150.research.scratch.maintest"};
            String[] env = {"CLASSPATH=" + System.getProperty("java.class.path")};
            Process proc = Runtime.getRuntime().exec(cmd, env);
            std_out = new response(proc.getInputStream(),System.out);
            std_out.start();
            std_err = new response(proc.getErrorStream(),System.err);
            std_err.start();
            doStream = new DataOutputStream(proc.getOutputStream());
            std_in = new outputer(doStream);
            std_in.start();
            int exitVal = proc.waitFor();
            System.out.println("ExitValue: " + exitVal);
            proc.destroy();
            doStream.close();
        catch (Throwable t)
            t.printStackTrace();
    public static void main(String args[])
        new WindowsExec();
}Message was edited by:
sabre150

Similar Messages

  • What is terminal all about?

    I have a q ,what is terminal all about? I think that for every possiible job, there are gui-applications,I mean really for everything.. can you tell me one usefull thing that requires the use of terminal? I mean what work can be done with it? I'm not talking about issuing several commands and see the network or processor workings, that's ok , but for what else can be used terminal? obviously it is not suitable for programming or text-editing.. what can be done better with terminal and terminal like programs, that can't be done with gui-applications? why on movies and such,computer gurus are always working in black screen and letters only environment?? what are they doing?
    Message was edited by: rumencho

    rumencho wrote:
    obviously it is not suitable for programming or text-editing..
    Really? That is the absolute best use for the Terminal. I always start programming from a Terminal window.
    what can be done better with terminal and terminal like programs, that can't be done with gui-applications? why on movies and such,computer gurus are always working in black screen and letters only environment?? what are they doing?
    That's just movies and, personally, I prefer a black-on-white traditional page background that is more common on Macs. Even if I'm working on Linux, another savvy programmer could probably tell I am a Mac person at heart just by looking at my terminal windows.
    The easiest answer is that the Terminal, or, rather, command-line applications narrow your input to one path, the standard input, and your output to two paths, standard output and standard error. That is extraordinarily helpful because it reduces the problem space and allows you to focus. In fact, just having two output paths (one for regular output and one for errors, is actually quite a hassle).
    Using these standard pipes, I can sting multiple programs together and have them work together to do very complicated things. In a GUI environment, you would need one GUI program that can do everything, which really doesn't exist. Plus, in the command line world, one data stream is the same as the next, no matter where it comes from. I can write a command line program that reads data from standard input and you can just type input into it. You could also send a file into it. You could also hook it up to a stream of network data. If you really want, you can even write a fancy GUI that sends data to it. The user on the other end will never know the difference.

  • All video streaming stops

    All video streams (NBC, ABC, Netflix) stop playing and require a system reset to begin playing again. When one service's video stops, all stop until the reset. Everything else still works. This began about a week ago on our iPad 1. Ideas?

    I've tried both things, but video still stutters.. Have also tried removing profile, and complete reinstall of firefox.
    I'm on 24 Mbit cable and the only user atm. IE and Chrome seems to work without stuttering.
    I've having this stuttering every ~5th second, like a small "1/4 sec buffering".

  • I have frequent instances of my Macbook Pro beeping 3 times and then I have to forcefully shut it down by pressing the power button. What is this all about? Please help. Thank you.

    I have frequent instances of my Macbook Pro beeping 3 times and then I have to forcefully shut it down by pressing the power button. What is this all about? Please help. Thank you.
    I saw this report being sent to Apple:
    Interval Since Last Panic Report:  581719 sec
    Panics Since Last Report:          10
    Anonymous UUID: F4CF708D-D85C-4EC5-8047-4FC22C6B03AF
    Fri Mar  7 13:00:14 2014
    panic(cpu 0 caller 0xffffff80002d1208): Kernel trap at 0xffffff800020c590, type 14=page fault, registers:
    CR0: 0x0000000080010033, CR2: 0x0000000000000000, CR3: 0x0000000007541000, CR4: 0x0000000000040660
    RAX: 0xffffff8000000000, RBX: 0xffffff800d35a870, RCX: 0xffffff800cf55cd8, RDX: 0xffffff80008a8fcc
    RSP: 0xffffff805e5f3d60, RBP: 0xffffff805e5f3da0, RSI: 0x000000001dcd6500, RDI: 0xffffff800d168778
    R8: 0x0000000000000001, R9: 0xffffff805e5f3e88, R10: 0x0000000000000011, R11: 0x0000000000000000
    R12: 0x0000000000000000, R13: 0xffffff800d168770, R14: 0xffffff800d168778, R15: 0x0000000000000000
    RFL: 0x0000000000010082, RIP: 0xffffff800020c590, CS:  0x0000000000000008, SS:  0x0000000000000010
    Error code: 0x0000000000000000
    Backtrace (CPU 0), Frame : Return Address
    0xffffff805e5f3a00 : 0xffffff8000204d15
    0xffffff805e5f3b00 : 0xffffff80002d1208
    0xffffff805e5f3c50 :
    Model: MacBookPro8,1, BootROM MBP81.0047.B27, 2 processors, Intel Core i5, 2.3 GHz, 4 GB, SMC 1.68f99
    Graphics: Intel HD Graphics 3000, Intel HD Graphics 3000, Built-In, 384 MB
    Memory Module: global_name
    AirPort: spairport_wireless_card_type_airport_extreme (0x14E4, 0xD6), Broadcom BCM43xx 1.0 5.100.198.104.5)
    Bluetooth: Version 2.4.5f3, 2 service, 12 devices, 1 incoming serial ports
    Serial ATA Device: Hitachi HTS545032B9A302, 298.09 GB
    Serial ATA Device: OPTIARC DVD RW AD-5970H
    USB Device: FaceTime HD Camera (Built-in), 0x05ac  (Apple Inc.), 0x8509, 0xfa200000 / 3
    USB Device: Hub, 0x0424 (SMSC), 0x2513, 0xfa100000 / 2
    USB Device: BRCM2070 Hub, 0x0a5c  (Broadcom Corp.), 0x4500, 0xfa110000 / 5
    USB Device: Bluetooth USB Host Controller, 0x05ac  (Apple Inc.), 0x821a, 0xfa113000 / 8
    USB Device: Apple Internal Keyboard / Trackpad, 0x05ac  (Apple Inc.), 0x0245, 0xfa120000 / 4
    USB Device: Hub, 0x0424 (SMSC), 0x2513, 0xfd100000 / 2
    USB Device: IR Receiver, 0x05ac  (Apple Inc.), 0x8242, 0xfd110000 / 3

    Hmm. The problem still may be the RAM - Apple buys the RAM it puts in its machines from third-party vendors (usually Hynix) so it could be a RAM problem.
    There are a couple of things that you can do yourself before taking your machine into an Apple Store or an AASP... download and run an application named Rember that will run a RAM test for you - let it run for a couple of hours or even overnight. If it turns out that your RAM is faulty, Rember will let you know. If it is faulty, then you have a couple of options - replace the RAM yourself or (particularly if you're under warranty still) take the machine to an Apple Store or AASP and have them replace the RAM.
    If Rember finds no fault with the RAM, then you'll need to take it into an Apple Store/AASP and get a free diagnosis on the machine. Three beeps do usually indicate faulty RAM, but if it tests good with Rember you likely have another problem - it could be something as simple as the RAM, somehow, not seated correctly or signs of another hardware problem.
    Run Rember first... call back with results.
    Good luck,
    Clinton

  • My rue la la app for ipad suddenly dosent work so I deleted it now when I try to reinstall it the app store says that it not available in the us. It is still on my Iphone and working properly. What is this all about?

    My rue la la app for ipad stopped working. I deleted the app and tried to reinstall it,  it is no longer available in the app store and when I research it on safari and find it when i try to install it says that it is not available in the us store. What is that all about?

    My app did the exact same thing. It is still unavailable on the App Store and when Rue La La's site directs you to download their app, the "not available in the U.S. message appears. This happened to me last night. The app wasn't working, I deleted it and was just going to reinstall but was unable to find the app. I figured it was some glitch but I have tried multiple times this afternoon to no avail.

  • HT1386 I synced (updated) my iphone to itunes and some songs were deleted from my iphone playlist on my phone.  On the computer, a circle is next to the song and the title faded out.  What the heck is that all about and how do I get my songs back onto my

    I synced (updated) my iphone to itunes and some songs were deleted from my iphone playlist on my phone.  On the computer, a circle is next to the song and the title faded out.  What the heck is that all about and how do I get my songs back onto my phone playlist?  Never happened before.  My software is up to date?

    http://support.apple.com/kb/HT2519

  • When I start up FCPX, the timeline and the clips don't highlight in yellow. I have to double-click to get them to highlight and it's in white. What's this all about?

    The system seems sluggish, as well. I can't find anything in help that describes what this is all about.

    Are you using the Select tool when trying to click on clips?  Might try hitting "A" on the keyboard just to be sure.
    ~D

  • I have read up on all about crashes and i cant even open it in safe mode :( i have tried deleting it and reinstalling it but the problem still persists. What would you suggest i do and is there any way i canget hold of firefox 6 for mac?

    i have read up on all about crashes and i cant even open it in safe mode :( i have tried deleting it and reinstalling it but the problem still persists. What would you suggest i do and is there any way i canget hold of firefox 6 for mac?

    Does the regular Firefox 8 release version work or does the version crash as well?
    *Firefox 8.0.x: http://www.mozilla.com/en-US/firefox/all.html
    Create a new profile as a test to check if your current profile is causing the problems.
    See "Basic Troubleshooting: Make a new profile":
    *https://support.mozilla.com/kb/Basic+Troubleshooting#w_8-make-a-new-profile
    There may be extensions and plugins installed by default in a new profile, so check that in "Tools > Add-ons > Extensions & Plugins" in case there are still problems.
    If that new profile works then you can transfer some files from the old profile to that new profile, but be careful not to copy corrupted files.
    See:
    *http://kb.mozillazine.org/Transferring_data_to_a_new_profile_-_Firefox

  • Messages has replaced all my text with a load of letter A's in boxes. What is that all about. When I type a new one it is fine until I hit enter then the same thing applies. Has anyone a fix for this?

    Messages has replaced all my text with a load of letter A's in boxes. What is that all about. When I type a new one it is fine until I hit enter then the same thing applies. Has anyone a fix for this?
    Picture below, many thanks for your help.
    Jason

    Back up all data before proceeding.
    Launch the Font Book application and validate all fonts. You must select the fonts in order to validate them. See the built-in help and this support article for instructions. If Font Book finds any issues, resolve them.
    Start up in safe mode to rebuild the font caches. Restart as usual and test.
    Note: If FileVault is enabled in OS X 10.9 or earlier, or if a firmware password is set, or if the startup volume is a software RAID, you can’t start in safe mode. In that case, ask for instructions.
    If you still have problems, then from the Font Book menu bar, select
              File ▹ Restore Standard Fonts...
    You'll be prompted to confirm, and then to enter your administrator login password.
    Also note that if you deactivate or remove any built-in fonts, for instance by using a third-party font manager, the system may become unstable.

  • Sync phone to computer and the process a significant amount of my contact list.  All "A"s, all but 2 B's, all but 4 c's then left everything else as is.  What's that all about and can I retrieve what was lost?

    sync iphone to computer and in the process a significant amount of my contact list was deleted.   All "A"s, all but 2 B's, all but 4 c's then left everything else as is.  What's that all about and can I retrieve what was lost?

    iTunes Store- Transferring purchases from iOS device or iPod to a computer
    Downloading past purchases from the App Store, iBookstore, and iTunes Store
    How to dowload purchased music

  • My Black Macbook froze using Safari.  I forced quit and restarted.  Before the chimes there was a single buzz, from below the keyboard.  What's that all about?

    My Black Macbook froze using Safari.  I forced quit and restarted.  Before the chime, there was a single buzz, from below the keyboard.  What's that all about?

    http://support.apple.com/kb/HT2341
    Might be RAM related if the above tip describes what happened.
    If not, and your data is not backed up, and it won't startup, read this tip:
    https://discussions.apple.com/docs/DOC-1689

  • My iPhone just said "SIM failure" and now says Invalid SIM in the upper corner. What's this all about?

    My iPhone just said "SIM failure" and now says Invalid SIM in the upper corner. What's this all about?  Any ideas on how to resolve this.

    Looks like the Sim card had a catastrophic failure. Burnout, short somethng like that.
    You can try to take out the tray and reseat the sim card inside and see if that gets it back.
    Also try resetting the phone at least once by holding down the home and power buttons until the Apple Logo shows up.
    If none of this works you'll have to contact your cell carrier to get a new sim card, as it probably fried and is no longer functional.

  • I am unable to update my incoming mail since 9/21/12  What's that all about?

    I can't update my new mail since 9/21/12 what's that all about?

    That's all about you and your mail provider. It has nothing to do with Apple, and certainly nothing to do with the people in this user-to-user forum. And based on the information you have provided thus far unless there happens to be a psychic monitoring the forum no one can help you.

  • HT3669 HP 2.16.1 downloading "updating" 3 times in 1 day? What's this all about?  I'm using latest OSX  on MBPro

    Hewlett Packard (HP) Printer Software Update ver. 2.16.1 has auto-installed/downloaded twice within the past few days and now, today, the App Store wants to download 2.16.1 HP Printer Software Update for a 3rd time!?! Same version all 3 times. What’s this all about? Is something acting up or is this normal? Really strange that it'd want 3 copies of 2.16.1....
    Please advise what I should do.
    I’m using latest Mavericks OSX (10.9.2) on Macbook Pro (mid-2012).
    Thank you,
    A
    Below is a screenshot in case I made no sense explaining the problem above.

    I don't know the cause and I haven't heard of that before, but
    I think you should try some generic maintenence:
    Startup from the Recovery Partition, and repair the hard drive and repair permissions with disk utility.
    http://support.apple.com/kb/ht4718
    (just read the first paragraph)

  • Confirming, indexing, creating peak file. What's this all about?

    Althought I'm new to PrPro (see my very first post, it was the that I just started using this app), premiere already ate me that anywhere I go, when it comes to video editing, I am in its belly. But still I want an explanation regarding (again) about this message that's appearing in the status bar: 'conforming ?????.mpg". I don't really understand what's this all about. A little explanation is a lot to me. But what I am concerning about this thing is, it seems to be endless. PrPro had done already on all of my assets, conforming, creating peak files, indexing, but it still keeps on doing it again and again. Is there a problem with my audio/video files?
    During the first time of my use, I didn't mind. I didn't even notice it. But now I started to be concerned with it since I my pc really slows down when PrPro starts this seemingly perpetual activity. If there's a problem somewhere else please help me.

    Did you notice that you make the same mistake as one of our regulars here, the_wine_snob, otherwise known as Bill Hunt, in leaving out one 'a' in my last name? I'm not offended but wonder if that is a human trait to not overdo it and two 'a'-s may be too much?
    I resemble that comment! Harm, you have to realize that I am from Mississippi, and everyone is known as Billy Bob, Joe Bob, or Bubba. We had no Harm Millaards - too many double vowels and consonants for us. At least this helped, when I signed up for a bunch of X-rated sites, as Harm Millard...
    OK, where were we? LameTiger (check that spelling, as I think I got it wrong again and apologize profusely), when one has non-standard footage, three thing need to happen: the files need to be indexed, the Audio must be Conformed (CFA files) and the Waveform Display (PEK) files must be created. Depending on the number of files, their Duration and one's computer's speed this can take from moments, to maybe 20 mins.
    If you have not just loaded up this Project, then gone for a cup of coffee, or tea, I urge you to do so. There is a tiny progress bar in the very lower-right of the GUI, that traces this. Let it happen, and be patient. I know that this sounds like a scene from the Karate Kid, but it's important. Many systems will crash, if one tried to do anything, before this process completes. I can work (albeit slowly), during the process. Many cannot.
    Now, if you HAVE patiently waited this process out, and it has completed, AND the next session yields the exact same thing, then something is not quite right. Could be files getting moved, deleted, or otherwise not available to PrPro, or some setting in one's Scratch Disks, or some other problem.
    Hope that a bit of patience, and a cup of Darjelling helps. Please let us know.
    Good luck,
    Hunt

Maybe you are looking for

  • How to sync iPhone calendar with iCal on Mac?

    When I migrated to iCloud, I lost all iCal data on my computer, but still have it on my iPhone. Any way to force iPhone calendar data onto my Mac? I have tried refreshing the calendar and turning the calendar on and off in my Mac's iCloud preferences

  • Display port connect to pc using imac as display.

    hi guys i recently got the imac 27inch. i would like to know if i connect the display port from my pc to the imac, should i on the power for my imac too ? as i was told that imac can use as a external monitor as long and connected to a display port f

  • Used vs new MacBook Pro?

    I need to buy a new machine and am considering a two-year-old, 17" MacBook Pro, with the Leopard OS. (I currently work on an iMac G5.) What problems do you foresee in buying a two-year-old machine? What are pros and cons of it vs. a new machine with

  • Automating renaming of business objects reports

    We have some 5000 reports which are crystal and webi reports.I need to open each of these reports and rename the reports to a new name.For eg, the report old name could be like "webidocument" and I would like to make the new report to be named as  "w

  • HT4059 Why can't I open my books now?

    Just replaced broken glass ipad2 unit and reloaded my iBooks but I can't open the book I was reading or any others. Any suggestions?