Problems with Runtime.getRuntime().exe and getting output. Please Help me!!

I'm creating a program that runs the followings programs written in C and compiled with gcc:
==========================The first C program====================================
#include<stdio.h>
void leia();
main()
int x = 20;
int y = 2;
printf( "Marcinho e Danny\n" );
printf( "Te\n" );
printf( "Vida\n" );
printf( "Marciorja: %d.\n", x * y );
===============================================================================
==========================The second C program====================================
#include<stdio.h>
void leia();
main()
int x = 20;
int y = 2;
printf( "Marcinho e Danny\n" );
printf( "Te\n" );
printf( "Vida\n" );
printf( "Marciorja: %d.\n", x * y );
scanf( "%d", &x ); //This is the statement added to the latter C program.
===============================================================================
I compiled this C program and generates the a.exe program. I have the following Java program:
==================================================================================
import java.awt.Color;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import javax.swing.JFrame;
import javax.swing.text.BadLocationException;
import javax.swing.text.EditorKit;
import javax.swing.text.MutableAttributeSet;
import javax.swing.text.Style;
import javax.swing.text.StyledDocument;
import javax.swing.text.StyledEditorKit;
public class Teste
private BufferedWriter out;
private BufferedReader in;
private Style stylePrompt;
private LeitorDeEntrada le;
private String entrada = "";
private AreaDeEdicao areaDeTexto;
Process p = null;
public Teste( AreaDeEdicao areaDeTexto )
this.areaDeTexto = areaDeTexto;
public void runCommand( String command ) throws IOException
StringTokenizer strTokenizer = new StringTokenizer( command );
String mainCommand = null;
String argument = null;
StyledDocument doc = areaDeTexto.getStyledDocument( );
String[] prefix = new String[] { "cmd.exe", "/c", command };
p = Runtime.getRuntime().exec( prefix, null, new File( System.getProperty( "user.dir" ) ) );
in = new BufferedReader( new InputStreamReader( p.getInputStream( ) ) );
out = new BufferedWriter( new OutputStreamWriter( p.getOutputStream( ) ) );
out.flush();
Thread t = new Thread( )
public void run( )
super.setName( "Marcio" );
execute( );
public void execute( )
String c = null;
try
if( !in.ready( ) )
try
this.sleep( 1000 );
catch( InterruptedException e2 )
e2.printStackTrace( );
System.out.println( "in.rea: " + in.ready( ) );
c = in.readLine( );
catch( IOException e )
e.printStackTrace( );
String str = "";
while( c != null )
str = c + "\n";
try
areaDeTexto.getDocument( ).insertString( areaDeTexto.getDocument( )
.getLength( ),
str, null );
catch( BadLocationException e3 )
e3.printStackTrace( );
try
c = in.readLine( );
catch( IOException e2 )
e2.printStackTrace( );
areaDeTexto.setCaretPosition( areaDeTexto.getDocument( )
.getLength( ) );
try
in.close( );
catch( IOException e1 )
e1.printStackTrace( );
t.setDaemon( true );
t.start( );
le = new LeitorDeEntrada( );
areaDeTexto.addKeyListener( le );
public static void main( String[] args )
JFrame janela = new JFrame( );
AreaDeEdicao areaDeTexto = new AreaDeEdicao( new MyDocument( ) );
areaDeTexto.setBackground( Color.black );
areaDeTexto.setForeground( Color.GREEN );
janela.getContentPane( ).add( areaDeTexto );
Teste teste = new Teste( areaDeTexto );
try
teste.runCommand( "a.exe" );
catch( IOException e )
e.printStackTrace( );
janela.setSize( 500, 300 );
janela.setVisible( true );
class LeitorDeEntrada extends KeyAdapter
public void keyPressed( KeyEvent e )
char c = e.getKeyChar( );
System.out.println( "keyPressed" );
try
if( c == '\n' )
areaDeTexto.getDocument().insertString( areaDeTexto.getDocument( )
.getLength( ),
c + "", null );
out.write( c + "" );
out.flush();
catch( BadLocationException e2 )
e2.printStackTrace( );
} catch (IOException e2) {
e2.printStackTrace();
==================================================================================
This Java program is very simple. It runs the a.exe using the method Runtime.getRuntime().exec and gets input for a.exe from a JTextPane and shows the output in the same JTextPane.
If my a.exe represents the binary code of the first C program the text in the JTextPane is the correct output of the a.exe. But, if my a.exe represents the binary code of the second C program, the JTextPane shows the messages ( "Marcinho e Danny\n", "Te\n", "Vida\n", "Marciorja: %d.\n") after I enter the value claimed by the scanf.
I tested my Java program running programs that require input and all have the same behavior:.
What can I need to do to solve this bug?
I read other posts with the same problem and nobody answers what is the problem.
I'LL pay 10 Duke dollars to the first that answers me.

The second C program with the statement fflush( stdout ) produces the right output.
#include<stdio.h>
void leia();
main()
int x = 20;
int y = 2;
printf( "Marcinho e Danny\n" );
printf( "Te\n" );
printf( "Vida\n" );
fflush( stdout ); //added statement.
printf( "Marciorja: %d.\n", x * y );
scanf( "%d", &x ); //This is the statement added to the latter C program.
but what can I do to run C programs that doesn't flush the stdout?

Similar Messages

  • Problems with Runtime.getRuntime().exec in Windows 2000

    Hello,
    I have a batch file that I want to run from my java application. My code is the following:
    try {
            Runtime.getRuntime().exec("cmd.exe /c C:\\temp\\shortcut.bat");
    } catch (Exception e) {
         System.out.println(e.getMessage());
    }I was developing on windows XP and it worked just fine. But then I tested it on windows 2000 and it didn't work. The batch file is okay, because if I run the batch file myself it works just fine, even from the command line. I get no errors what so ever, it just doesn't do anything...
    Can somebody help me with this?
    thx in advance

    thank you all so much
    I figured it out... It was a combination of two things that went wrong.
    First one: in my batch file I had:
    cd C:\tempwhich worsk fine in XP, but in it doesn't in 2000. In 2000 it has to be:
    C:
    cd \temp But just changing that wasn't enough, I also needed the "start"
    Now it works just fine on 2000, hopefully it'll still work on xp as well.
    THX!

  • Problem with Runtime.getRuntime().exec

    Hi ,
    i'm using jBuilderX and windows 2000 server . My problem is that i can't
    find why
    in my code it doesn't work this:
    import java.lang.*;
    String command = new String("c:\\testd\\testf.bat"); // testf.bat -
    batch file
    Runtime.getRuntime().exec(command); // it doesn't
    have any effect
    Thanks in advance,

    What's it supposed to do?
    I can definitely help you on this 1, but I'd really like to see your streamoutputs. You can get these from the Process object that is created, but you'll need to add some threaded listeners to get the data.
    Is this possible?

  • VERY BIG PROBLEMS WITH MY ZEN MICRO AND MEDIASOURCE! PLEASE PLEASE PLEASE HELP ME! PLEASE RESPOND

    Ok so a while back I had to give up my computer because it wasn't working.
    I thought that with my new computer I'd be able to transfer all of my music from my zen micro onto my new computer.
    Now my new computer is set up and I have installed creative mediasource and everything. I started to transfer my music from my zen onto my computer. My first 2 songs transfered successfully onto my computer. On the third song, I get this message:
    "Unable to read file, file may be in use, missing, or corrupted."
    I thought that maybe it was just that one song so I shrugged it off. But then it says the same thing for every single other song that i have! Only my first 2 songs out of my entire music library on my zen will transfer!!!
    Please i really need your help!!!
    And say that there is no hope in getting the rest of my songs to transfer and i have to download 094 songs from limewire? I'll surely be arrested for downloading that much! What should i do if i must download all of them?
    And one more problem with my zen: Some of my Jump Little Children songs are doing something weird. The song will be fine and then a clip from another song will play during it! And then press next and it just keeps playing all of my Jump songs in order even though my player is on shuffle and they do the same thing with the clip from another song interupting it. Whats going on?
    Most importantly though, i really need the questions answered about transfering from my zen to my computer because i'll be getting a new player soon. But this is my entire music library at stake!! PLEASE RESPOND!!!

    Might try this:? http://forums.creative.com/creativel...mp=true#M95059

  • Problem with your Xperia Z1 and Service Centre NOT Helpful

    Hi, 
    If you are from India and If you are an Xperia Z1 owner, and facing problems with your phone and the service centre and customer care totally unhelpful, Contact me. We are starting a self help forum very soon. 
    If you feel you have been cheated by Sony, Contact me. Let us sort it out.

    thereis already a self-help forum
    two, actually
    the one is this one
    the other is xda-developers, who probably will tell you to install cyanogenmod, go into recovery and delete dalvik cache three times

  • Uninstalling Oracle Client 8.0.5.0 And Getting Error - Please Help

    Hi Gang
    I have installed the Oracle 8.0.5.0 client on a server and now I can't get it off. When I run the install program and select everything to uninstall, it starts to process and then gives me the following error.
    It was not possible to find a value for the variable 'rdbms80' in '$ORACLE'. It is therefore not possible to remove Required Support Files. Please restore the binding for 'rdbms80' in '$ORACLE' in order to remove Required Support Files.
    Could you PLEASE help with this?
    Thanks
    Andy

    I guess results are unpredictable when using such an old client, that was not written to handle pipelined functions. Presumably in its communication with the server it is sending the wrong information because it doesn't know what datatype it is dealing with.
    You will also hit problems dealing with object and collection types in general, timestamps, intervals and WITH clauses. I've had no problems using the 10g client against a 9.2 database. Not only do you get a better version of SQL*Plus, but it solved some similar problems within PL/SQL Developer.

  • Problems with WRT54 V.7 (V7.00.4) :please help me!...

    Hi,
    I've just installed (two days ago) this device and it's so annoying.i've been with the chat support of linksys for hours and they could not help!
    These are the problems:
    My laptop "see" the router but u can't access the internet,although that when i try to check and connect the laptop via direct cable it's doing that with no problem.
    U can see that the signal is strong but u just cannot access the net.
    My second device:an asus a636 pocket pc can see the router only on a few times:most of the time i just can't "See" the router,and when it does see it sometime,u cannot surf the internet as well.
    (i must point out that i surf the internet using th pocket pc with no problem on many public places...)
    I tried to restart,reinstalling the firmware (v7.00.4) a few times,and configured the router again,but it didn't solve anything.
    To add to that:the setup cd/wizard didn't work at all and started the debugger of the windows (Win2000),and even when u try to download the setup from linksys site,it's doing the same and starting the debugger,so i installed the 7.00.4 firmware using the tftp.exe program.
    What else can i do so this device can work properly??it's so frustrating!!!
    Please help whoever u are.
    Thanks in advance!!!

    Hi… Try changing the Wireless Channel on this router and check the Wireless Security mode. Make sure it is supported by your OS / wireless adapter. Select proper security key and try to connect to this wireless network. Once connected, check the IP address on the PC and try to ping to Router and DNS servers. Revert back with your findings.

  • I have problems with importing music to iTunes, can somebody please help me?

    I have all my music organized on an external hard disc in folders for each artist and album, but I can only import some of the folders. It’s like iTunes isn’t registering specific folders, and just skip these folders while the rest of the folders is added as normal. I have tried to add the missing folders manually but it doesn’t help.  I simply can’t add some music to iTunes, what am I doing wrong? Thanks!

    It's the file attributes. The files will add but when you try to add a folder it doesn't work. You can get a bulk attribute changer progeam like BulkFileChanger and get rid of the Hidden and archive attributes, This fixed my problem.

  • Problems with AIM on Blackberry 7100i...Please help

    I got the 7100i off ebay with AIM preinstalled...it didn't work.  I then called nextel and they told me that there was a compatibility issue with the new AIM and this phone...so the guy gave me a web address to download the aim from.  It wasn't an address from AIM.com or Blackberry.com...and of course I didn't write it down...and now Nextel tells me that they have never had issues with AIM and this phone.  I can download and install AIM on the phone but when I put in my correct (and yes it is the correct one because I also tried putting the same password in my computer's AIM) it tells me that "service not enablesd for this handheld" but since it's third party software...Nextel can't help me.  Anyone know how to fix this?

    The best advice I can offer is to dump the AOL AIM client altogether, and use a third-party instant messaging application that supports AIM.
    For example, Adium X is a full featured IM client that supports AIM as well as many other IM protocols.
    It's very stable on Tiger, and it's light years ahead of the official AIM client from AOL.
    Try it out!

  • TS3899 How do I fix my email account on my iphone 5? I have been having problems with my hotmail on my phone. Please help.

    At first I deleted my account as suggested by the support article and instaled my hotmail account again.
    Now I don't have access to my email anymore.
    Please help.

    No, hotmail is having problems:
    http://bostinno.streetwise.co/2013/08/15/hotmail-outage-hotmail-is-down-for-user s-still-photos/
    http://www.engadget.com/2013/08/14/outlook-outage/
    http://www.infoworld.com/d/applications/microsofts-skydrive-outlookcom-are-down- some-users-224940
    http://mashable.com/2013/08/14/outlook-down/
    http://techcrunch.com/2013/08/14/microsoft-acknowledges-outlook-com-messenger-sk ydrive-outages/

  • HT4623 Problem between iPhone 4, PC and iTunes.  Please help!!

    I inserted the plugs between my iPhone 4 and my PC.  And then, the iTunes connected automatically.  However, I dont know why the update function cannot stop at my iTunes and my mobile cannot run again automatically.  Please help.  Tks

    It could be caused by a weak phone connection.

  • HT5945 Why does Instal Java SE 6 keep popping up and when I attempt to install it says that there is a problem with the internet connection ???  Please help

    I keep getting a pop up reminder to install Java SE 6.  When I attempt to install it an error occurs saying that there is a internet connection problem and the Java cannot be intalled.  This thing pops up every 15 minutes.  Am I doing something wrong?  Thanks for any help

    OK, so you don't have a working iTunes.
    What I would like to do now is to try installing each iTunes component separately.
    First uninstall the 5 iTunes programs that you have installed.
    You should have iTunesSetup.exe saved in a folder on your PC, probably in the downloads folder. If not download and save it now.
    Open the folder containing iTunessetup.exe with explorer.
    Next open notepad and copy the following 3 lines into it.
    md temp
    itunessetup /extract temp
    pause
    Save the file as extract.bat into the same folder that contains the itunes installer.
    Open the downloads folder and you should find the extract file that you saved. Double click on it and a black window will open telling you what it is doing. When its finished, press any key to continue.
    You should find that a folder called temp has been created containing all the itunes msi files.
    Install in this order by double clicking on them:
    Apple Application Support
    Bonjour
    Apple Mobile Device Support
    Apple Software Update
    Quicktime
    iTunes
    If one of the installs fails, stop and post the error message in full. I am hoping that by doing this separately we will get a better error message.

  • Cannot download iTunes. Problem with Runtime errror what do I do please?

    I need to know what to do. I keep getting a message telling me iTunes is trying to open runtime incorrectly and to contact iTunes. But of course thats easier said than done. All I want to do is download the update. To be honest I'd be content if I could redown load the old version. Any Ideas please?

    Go to Control Panel > Add or Remove Programs (Win XP) or Programs and Features (later)
    Remove all of these items in the following order:
    iTunes
    Apple Software Update
    Apple Mobile Device Support (if this won't uninstall move on to the next item)
    Bonjour
    Apple Application Support
    Reboot, download iTunes, then reinstall, either using an account with administrative rights, or right-clicking the downloaded installer and selecting Run as Administrator.
    The uninstall and reinstall process will preserve your iTunes library and settings, but ideally you would back up the library and your other important personal documents and data on a regular basis. See this user tip for a suggested technique.
    Please note:
    Some users may need to follow all the steps in whichever of the following support documents applies to their system. These include some additional manual file and folder deletions not mentioned above.
    HT1925: Removing and Reinstalling iTunes for Windows XP
    HT1923: Removing and reinstalling iTunes for Windows Vista, Windows 7, or Windows 8
    tt2

  • Problems with my new MSI N580GTX-M2D15D5/OC Please help

    Hi, purchased the above card from kuala lumpur, Malaysia on the 19th February 2011 when I visited Malaysia. Installed the card on my Core i7 950 rig.
    My card is MSI N580GTX-M2D15D5/OC 3DMark 11 edition.
    Had issues installing the card, blue screened many times. I was using a GTX295 with a 8800GT to handle physx earlier with no problems what so ever.
    So I removed my 8800GT and checked only with the new GTX580, the card runs as an OC edition, but now the problem is I experience random freezing when I run 3D Mark 11 (It says " windows focus was lost" during bench mark running) and Crysis.
    Even Mafia II bench marks gives me a rather low rating as "D", where I was getting a comfortable "C" with my earlier 295 arrangement. Crysis crashed many times too.
    Posted here is a screen shot of my GPU Z and afterburner shows a 1000 mv. And I am using 266.58 drivers.
    My Rig specs are, if it helps:
    1.ASUS Rampage III Formula LGA 1366 Intel X58 SATA 6Gb/s USB 3.0 ATX Intel Motherboard
    2. Intel Core i7-950 Bloomfield 3.06GHz 4 x 256KB L2 Cache 8MB L3 Cache LGA 1366 130W Quad-Core Processor
    3. CORSAIR DOMINATOR 6GB (3 x 2GB) 240-Pin DDR3 SDRAM DDR3 1600 (PC3 12800) Triple Channel Kit Desktop Memory
    4.Intel X25-M Mainstream SSDSA2MH080G2R5 2.5" 80GB SATA II MLC Internal Solid State Drive (SSD).
    5. Western Digital Caviar Black WD1001FALS 1TB 7200 RPM 32MB Cache SATA 3.0Gb/s 3.5" Internal Hard Drive -Bare Drive
    6. Seagate Barracuda 7200.11 ST31500341AS 1.5TB 7200 RPM 32MB Cache SATA 3.0Gb/s 3.5" Internal Hard Drive
    7. MSI N580GTX-M2D15D5/OC Graphic Card
    8. Corsair CMPSU-750TX 750-Watt TX Series 80 Plus Certified Power Supply
    9. Creative GigaWorks S750 700 Watts 7.1 Speaker
    10.Creative Sound Blaster X-Fi Titanium Fatal1ty Professional 70SB088600002 7.1 Channels 24-bit 96KHz PCI Express x1 Interface Sound Card
    11. ViewSonic 22" VX2255wmb widescreen LCD monitor
    12. Windows 7 Ultimate 64bit
    If I am to RMA the card it's going to complicate matters as I am living out of Malaysia.. can there be a VGA bios upgrade solution? I am kind of sad that I had to purchase this card..Please advice

    Quote
    Hi Swet, did all the testing in between my work, sorry I got late to reply.  Smiley
    It's like this. Managed to get 3D Mark 11 working back again after so many tries. I just disabled the screen saver, and it was okay after that. Strange isn't it?  
    with 1025mV I got a reading of P6350 and with 1038 I got P6365.
    we can assume this as 3D Mark 11 issue
    Quote
    D mark vantage running was okay. Completed Furmark bench successfully many times. No issues there.  http://www.ozone3d.net/benchmarks/furmark_score_190.php?id=147818
    Looks like to be Kombuster issue.. since Furmark can work fine. Kombuster is based on Furmark.
    If you apply reference clocks from AB does the issue described persist with Kombuster ?
    Quote
    Link received and will be checked, and also removed.[Not for public]
    I didn't go ahead with it without consulting you. Please be kind to check it out for me.
    Also I could play CRYSIS 2 Demo without any issue with 1025mV and 1038mV both.
    Temps were around 70-75 C. Is it okay.
    My personal preference is 1038mV.
    Well, what do you think? Thanks very much.  Smiley
    Quote
    Link received and will be checked, and also removed.[Not for public]
    I didn't go ahead with it without consulting you. Please be kind to check it out for me.
    I've check it and it's the same version as your current installed.
    E.g. flashing to this one will not change anything
    Quote
    Also I could play CRYSIS 2 Demo without any issue with 1025mV and 1038mV both.
    Temps were around 70-75 C. Is it okay.
    My personal preference is 1038mV.
    Well, what do you think? Thanks very much.  
    Check PM

  • Problems with MSI GeForce 7900 GT/GTO. Please Help!!!

    I purchased an MSI GeForce 7900 GT/GTO last summer. At first it was working fine. I would get the occasional automaic restart in the middle of a game, but other than that it was fine. Now, almost a year has past and the product I payed good money for isn't working as it should, to say the least. I get many artifacts in all the games I play. The artifacts are the same in each game, although they more numerous in some then others. The objects in-game are connected by "ropes". There are strange colors on the walls. Sometimes the screen starts flashing different colors and the artifacts become impossible to ignore. I've had to Ctrl-Alt-Delete out of a game numerous times only to be greeted with a flashing desktop. Then I have to do a hard restart. It seems that the problems are getting worse as time goes on. The artifacts were not this bad before, but now I can't play 30 min. of any game without having these graphical artifacts. The glitches are worst in the Tomb Raider: Aniversarry demo and Test Drive Unlimited. I also see the artifacts in Half Life 2 and Rainbow Six Vegas. I haven't overclocked my card at all and my fans are working as they should. The temperature of the card is running at 55 degrees at the moment. I believe during games it goes up to around 65 which I don't think is bad. I have installed the latest Nvidia drivers. I sent an email to customer service explaining to them what the problem was. In the email I asked them to email me back as soon as possible to let me know what information to send. I have yet to recieve a reply and its been almost a week. When I payed for the card I didn't expect that it would fall apart in less than a year. This is just outrageous and I am disgusted with the "customer service" that MSI has to offer.
    (Some of the artifacts, such as the flashing colors, couldn't be captured in a screenshot)
    http://aycu40.webshots.com/image/16599/2006113858383399657_rs.jpg
    http://aycu30.webshots.com/image/16709/2006271169703725903_rs.jpg

    Quote from: Blackwheel24 on 06-June-07, 04:46:04
    +3.3V/30A     +5V/45A     +12V1/18A
    have a try with better one, your VGA required at lease +26A on +12V.
    get a decent PSU, single rail with high amperes on +12V (30A or more are recommended)
    read here:
    PSU's---2 x 12v---The Dual Rail Myth
    Is your problem caused by your PSU?
    Good PSU recommendation:
    http://www.pcpower.com/products/viewproduct.php?show=S61EPS&view=techspecs  Silencer 610 EPS12V llarge single rail +12V @ 49A)
    other good suggestion can be found here:
    https://forum-en.msi.com/index.php?topic=105635.msg783148#msg783148
    https://forum-en.msi.com/index.php?topic=103299.msg757739#msg757739
    but 1st thing to test it, have a try VGA in another machine.

Maybe you are looking for

  • What is the diff b/w Conventional Path and Direct Path?

    What is the diff b/w Conventional Path and Direct Path? While doing exp/imp which one is best in peroformance Conventional Or Direct consider my Oracle is 9i (9.2.0) and Os is Solaris 9 Could you please clarify..... Thanks

  • Firefox stops responding when trying to access facebook.

    As of Sunday I cannot access Facebook. When I type in facebook in to the address bar Mozilla circle spins and then stops and eventually goes to "not responding." Every other website page I try to load is perfectly fine. And facebook page was fine as

  • Why can't I use my iTunes gift card to purchase an app?

    I received a $15 itunes gift card for my birthday and I redeemed the card on iTunes. The $15 is in my account but I can't use it to purchase an app for my mac at the app store. I heard other people had problems with the itunes and app store connectio

  • Why do I have to sign in every time use ibooks

    Since the ios7 update, almost every time I use iBooks it prompts me to sign into my appstore account.  This is new behavior and is aggrevating.  Why is it necessary?  Am I missing something?

  • OWSM: it's possible manipulate a xml string date with a policies ?

    Hello, It's the first time that i use the OWSM. The objecties of my project is reuse a old webservice deploy in the old application. The authentication of websercice is inside the structure string xml type. For example any service are the follow soap