Runtime.exec() makes program act weird

Hello
I have a problem with the runtime.exec() command?
I have created a program in vb.net with a tcpClient that opens a stream to a server.
When i execute the program myself it works fine, but when i run it through my java applet with runtime.exec() its suddenly hangs reading the stream?
I can't make it work, and its so weird that the program reads the stream several times and then just hangs, even though i can see in wireshark that packets are recieved.
Please help anyone who might know how to solve this :)

Read and implement the recommendations in all sections of [When Runtime.exec() won't|http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html].
db

Similar Messages

  • Is it okay to runtime exec external programs?

    I have a need to get statistics from a couple network devices. They allow public snmp and I looked around for libraries to do snmpwalk but there is not very good ones out there (one costs money). I would like to copy the snmpwalk binary to my programs bin directory and execute it with the proper parameters, then read in the results. Then I will take the results and do what I need with them.
    Is this generally frowned upon?

    I reason that if I don't care for platform independent I use external programs.
    For example if I know that my program will always run under Linux I use Linux internal programs.
    Use http://java.sun.com/j2se/1.5.0/docs/api/java/lang/ProcessBuilder.html.

  • External hardrive makes mouse act weird!

    G4 Laptop running OSX 10.4.11
    My mouse works fine, but as soon as i plug in my external harddrive (Firewire) the mouse won't work, or only the right button will work, or it will only draw "selection boxes" on the desktop.
    Anyone?

    Have you tried resetting the PMU? http://support.apple.com/kb/HT1431 . If it's power-related, that may fix it.

  • A problem with "Runtime.exec"

    Hello!
    I'm just trying to call a Fortran executable in a Java program.
    I'm a beginner in Java language and I believed Runtime.exec was the solution. My code :
    try {
    Process process = null;
    Runtime runtime = Runtime.getRuntime();
    process = runtime.exec("<name>.exe");
    catch (IOException eio) {
    System.out.println("Error -- " + eio.toString());
    When I run the project, there's no error, but the executable is not called.
    Can anybody help me?

    process = runtime.exec("Make sure// you have the right// path to.exe");

  • Runtime.exec() and subprocesses

    I am running a bat file through Runtime.exec(). Conetent of bat file look
    likes following
    E:\Progra~1\Brio\SQRServer\ORA\BINW\sqrw d:/brio/par/par_pqa.sqr
    ibprod/active1@pscore -oC:/TEMP/sqr.log -printer:pd 88
    d:/Brio_Reports/report1.pdf d:/brio/
    exit
    Now this batch file starts another executable program. That program creates
    a report in a particular directory and exit the process. When I run this
    file from command prompt it runs fine. But if I try same thing from
    Runtime.exec(), my program hangs.
    From windows process monitor tools it seems that it start a new process but
    that process never ends. If I end that process forcefully then pointer
    again returns to my java program.
    any idea how to solve this problem.

    Is there maybe any stdout or stderr (console so to say) output which is not taken care of when the thing is called from Java?

  • Make can't recursively call Make when run from Runtime.exec (for some user)

    This one is a little complicated. The afflicted platform is Mac OS X. It works fine on Linux, it seems, and even then, it does work for some Mac OS X users...
    First, the setup. I have a Java program that has to call GNU Make. Then, GNU Make will recursively call Make in some subdirectories. This results in the following Java code:
    String make = "make"; //on windows, I have this swapped with "mingw32-make"
    String workDir = ...; //this is programmatically detected to be the same folder that the parent Makefile is in
    Runtime.getRuntime().exec(make,null,workDir);This calls make on a Makefile which has the following line early on to be executed (this is only a snippet from the makefile):
    cd subdirectory && $(MAKE)When I fetch the output from the make command, I usually get what I expect: It cd's to the directory and it recursively calls make and everything goes smoothly.
    However, for one particular user, using Mac OS X, he has reported the following output:
    cd subdirectory && make
    /bin/sh: make: command not found
    make: *** [PROJNAME] Error 127Which is like, kinda hurts my head... make can't find make, apparently.
    I've gotten some suggestions that it might be due to the "cd" command acting wonky. I've gotten other suggestions that it may be some strange setup with the env variables (My Mac developer is implementing a fix/workaround for 'environ', which is apparently posix standard, but Mac (Mr. Posix Compliance...) doesn't implement it. When he finishes that, I'll know whether it worked or not, but I get the feeling it won't fix this problem, since it's intended for another area of code entirely...
    Also worth mentioning, when the user calls "make" from the terminal in said directory, it recurses fine, getting past that particular line. (Later on down the road he hits errors with environ, which is what my aforementioned Mac dev is working on). Although calling "make" by hand is not an ideal solution here.
    Anyways, I'm looking for someone who's fairly knowledgeable with Runtime.exec() to suggest some way to work around this, or at least to find out that perhaps one of the User's settings are wonked up and they can just fix it and have this working... that'd be great too.
    -IsmAvatar

    YoungWinston
    YoungWinston wrote:
    IsmAvatar wrote:
    However, for one particular user, using Mac OS X, he has reported the following output:One particular user, or all users on Mac OS?In this case, I have two mac users. One is reporting that all works fine. The other is reporting this problem.
    cd subdirectory && make
    /bin/sh: make: command not found
    make: *** [PROJNAME] Error 127Which is like, kinda hurts my head... make can't find make, apparently.If that is being reported on the command line, then I'd say that make wasn't being found at all.If make isn't being found, then who's interpreting the Makefile?
    It's also just possible that the make script on Mac isn't correctly exporting its PATH variable, though it seems unlikely, since this would surely have been reported as a bug long ago.
    I've gotten some suggestions that it might be due to the "cd" command acting wonky...Also seems unlikely. 'cd' has been around since shortly after the K-T extinction event.
    WinstonBy "acting wonky", I mean being given a bad work directory or some such, such that it's not changing to the intended directory.
    Andrew Thompson
    Andrew Thompson wrote:
    (shudder) Read and implement all the recommendations of "When Runtime.exec() won't" (http://www.javaworld.com/jw-12-2000/jw-1229-traps.html).
    Already read it. I already know the dreadful wonders of Runtime.exec. But in this case, it's been working fine for us up until one Mac user reported that make can't find make.
    Also, why are you still coding for Java 1.4? If you are not, use a ProcessBuilder, which takes a small part of the pain out of dealing with processes.Usually I do use a ProcessBuilder. I noticed that it usually delegates to Runtime.exec() anyways, and seeing as I didn't need any of the additional functionality, I decided to just use Runtime.exec() in this particular case.
    jschell
    jschell wrote:
    So print thos env vars, in your app and when the user does it.I'll look into that. It's a good start.
    -IsmAvatar

  • Using Runtime.getRuntime().exec(DOS Program) with Windows 2000.

    I am trying to spawn a DOS Program from within Java.
    On Win95/98/ME, I use
    Process     p = Runtime.getRuntime().exec("START /w command.com con /c myDOSProgram.exe");
    This works on these platforms. On Win 2000, I use
    Process     p = Runtime.getRuntime().exec("START /w cmd.exe con /c myDOSProgram.exe");
    It does not work at all.
    I have tried all combinations of using START, cmd.exe, con /c, etc.
    I can spawn a Windows App using
    Process     p = Runtime.getRuntime().exec("windows.exe");
    And it works fine.
    What does it take to spawn a DOS program from Java on the Windows 2000 op sys?

    Hi. I recently wrote a java GUI that calls a DOS program with mixed success. Here's the code I used to make the call:String osName = System.getProperty("os.name" );
    String[] cmd = new String[4];
    if( osName.equals( "Windows 2000" ) || osName.equals( "Windows NT" ) )
         cmd[0] = "cmd.exe";
         cmd[1] = "/C" ;
         cmd[2] = "VBDoc.exe";
         cmd[3] = fileName;
    else if( osName.equals( "Windows 95" ) || osName.equals( "Windows 98" ) )
         cmd[0] = "command.com" ;
         cmd[1] = "/C" ;
         cmd[2] = "VBDoc.exe";
         cmd[3] = fileName;
    else
         System.out.println(osName);
    Process proc = runtime.exec(cmd);Check out this article, it gives a good explanation of how to use the exec() call:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    Hope this helps!

  • Firefox makes some opengl programs work weirdly on windows 7, they minimize to taskbar unexpectedly

    firefox seems to cause programs which use opengl to act weird, it minimizes them to taskbar suddenly, unexpectedly. This ofcourse leads to me not being able to use this software while firefox is open
    == This happened ==
    Every time Firefox opened
    == when i changed to windows 7

    Hi! I have the same problem here. I develop a lot of OpenGL applications, and lately I've noticed that whenever I have Mozilla Firefox (3.6.4) opened, my OpenGL application fail to become 100% fullscreen as they should. Here is what it happens: first I execute the application, after a few seconds of flickering the window appears, but the taskbar is in front of the window and moreover the window of my OpenGL application is not focused, i.e. it won't receive any mouse or keyboard input. Even though I create this window with WS_POPUP and WS_EX_TOPMOST flags, and I properly change the resolution with ChangeDisplaySettings( &dmScrSettings, CDS_FULLSCREEN ). And I have to click once inside the window to make it 100% fullscreen and focused, BUT this doesn't work always.
    But if I close Firefox and try to execute the application again, everything works just fine, the OpenGL windows is now 100% fullscreen, topmost and focused.
    I don't know if this is related to Windows 7 ( i have Windows 7 Ultimate x64) or to this version of Mozilla Firefox, but i didn't have this issue while programming in XP or Vista. I also can confirm that it's not because my code, because I've test this issue with plenty other OpenGL samples downloaded from the internet, and the problem persists.
    I hope someone will fix this, thanks in advance!
    - Mike

  • Strange problem when a c++ program is triggered by Runtime.exec()

    I am working in linux system. I have 2 programs:
    1. one is a c++ program e.g. AAA. In this program, i use "system("gcc ...")" to call gcc to do some internal processing
    2. the other is a java program BBB. In this program, i use Runtime.exec("AAA") to run program AAA.
    case 1
    if I run c++ program AAA directly, everything goes well, gcc call via "system" is successful.
    case 2
    if I run java program BBB to trigger AAA indirectly, the AAA can be executed, but the system call (gcc call inside AAA) is failed.
    so, what is wrong? any hints? what is the solution to make case #2 work? I just want to use BBB to trigger AAA, and the system call should also be successful.
    thanks in advance for your help!

    "...but the system call (gcc call inside AAA) is failed."
    Isn't terribly descriptive, but I'm guessing that it complains it can't find gcc?
    If that's the case then it's because the call to Runtime.exec() runs the code in a shell with no idea where anything is, whereas when you run the C++ code straight it is running in the shell you kicked it off in. Something along those lines anyway.
    Someone else'll be able to tell you how to get it to work. I'm sure I've seen this sort of problem here several times.

  • Runtime.exec() - how to open new window for new program?

    Hi,
    I have searched through the forums but haven't found an answer to this one yet. I am using runtime.exec() to start up a new java program. At first I thought it wasn't running properly but, after checking task manager, I have discovered that the new program I open runs, it is just completely invisible to me. I am wondering how I can get the new program to run in a command window or something where I can monitor it.
    Thank you for your help,
    Drew

    Thank you all. After trying to figure out why the start command wouldn't work in the runtime.exec() call(not an executable - I am a dolt), I tried putting it in a batch file and it worked perfectly. Thanks for your help,
    Drew

  • Runtime exec problem to execute a C program

    Hi,
    I've spend lot of time trying to find a solution without success...
    My aim is to run a C program from a java application under linux. My C code is the following:
    #include <stdlib.h>
    #include <stdio.h>
    #include <string.h>
    main(int argc, char **argv){
    printf("hello world \n");
    Once compiled I run my java application wich run the binary through a runtime.exec().
    I followed the example given by
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    with the same input gobblers and threads.
    For some reason it doesn't work: nothing comes out...
    When I call "ls" instead of my binary it works perfectly!
    WHY??
    Any help would be greatly appreciated!

    Thanks for the reply.
    Yes it seems that JNI could be a solution, but it looks a bit complicated an maybe not so well adapted to my purpose.
    The executables I want to execute from my java application don't need any arguments.
    If JNI is really the only way I'll try to use it but is there any good reason why runtime exec doesn't work? It is supposed to execute any executable isn't it?
    cheers

  • Runtime exec MFC console program

    I'm trying to launch an MFC console program with some parameters
    but it doesn't work
    no exeception (but it looks like it has never been launched)
    I made a program which is not MFC that works in the same configuration
    But I need to launch an MFC one
    could some one help me??

    I found the solution
    it works with jdk 1.3 (3 parameters)
    when you launch the exe you must specify
    the working path
    runtime.exec("path/exename",null,"workingDirectoryPath");

  • Runtime.exec does not execute my program, but executes "ls"

    I am trying to run an exe from a Java program.
    The program that I want to run is an output of a gcc -o ICDDATA ICDdata.c
    Now when I use the Runtime.exec() and execute "ls", "cat" it is working fine without any errors.
    But when i try to give the file(ICDDATA) that was created with the gcc, it generates an error code of "11" or "10" and exits the process.
    Could anyone please let me know the reason why this is happenig and suggest and appropiate solution for this.

    When I give ICDDATA at the prompt, it is executing perfectly fine.
    But only when it is run inside the Java program its giving the error code 10.
    Here is the source code:
    ======================================
    public class InvokeInterface {
         This method takes two parameters and accordingly invokes one of the
         interface (ICD / Value).
         @Input : String, String
         @Return : void
         static void executeInterface(String processName, String debugOption)
         throws java.io.IOException     {
              String commandToExecute=". / ";
                   // The command that has to be passed to the Shell.
              if(processName.equals("ICD"))
                   commandToExecute="ICDDataRefresh";
              if(processName.equals("VALUE"))
                   commandToExecute="ValueDataRefersh";
              commandToExecute += " "+debugOption;
              System.out.println("..."+commandToExecute);
              Runtime runtime = Runtime.getRuntime();
              Process proc = runtime.exec(commandToExecute);
                   try {
                        if (proc.waitFor() != 0) {
                        System.err.println("exit value = " +
                        proc.exitValue());
              catch (InterruptedException e) {
                   System.err.println(e);
    ==========
    Thanks in Advance
    Ram

  • Does low disk space make my Macbook Pro act weird?

    Hi! I have an early 2011 15" MBP with a 750gb hard disk space. Just the other day, while I was using photoshop with my laptop, the screen went off so I had to reset it. My laptop acted weird after: doing a screen split (the right part goes to the left and vice versa), one time it had weird pixels that were scattered all over, recently, a blue striped screen. All of this froze my laptop by the way. And all of this happened after a few minutes of usage. And I noticed if I use photoshop, it would only take a little amount of time before it would act weird again compared to when I don't. All the times caused me to reset my laptop by holding the power button.
    Yesterday, it wouldn't boot past the gray screen after resetting about five times. But after it turned off by itself, I tried turning it on again and it booted normally. And I could use it normally again, but with extra care (using it beside an electric fan, checking the temperature with iStat pro).
    I tried the extended Apple Hardware Test but it told me no trouble was found.
    Another thing was, everytime my laptop froze and did the weird screen thingy, my laptop was hot.
    I tried to use it again yesterday to just surf the web, and after some minutes it was still functioning. But I remember one time I was only surfing the web, it did the split screen and froze after almost an hour or so.
    Also, my laptop heats up quickly compared before. And can stand being hot for a long time until now.
    I haven't used any heavy applications besides photoshop to test my laptop's weird behavior by the way.
    So I guess it's because of the laptop's heat. Because I can only use it for a very short time when using photoshop but I can use my laptop for a longer time when only surfing the web.
    I also noticed that if I was forced to reset my laptop and turn it on again, it would boot longer than normal. But if I was able to shut it down properly and turn it on again, it would boot normally.
    And, just a while ago, I remembered my laptop's disk space was only 14gb from 750gb (downloaded a lot of series since I bought my laptop). So maybe what's causing the heat was the low disk space. Just a guess.  So is it possible that my laptop is behaving weird because of the low disk space?

    The problem is back. But this time, it only happened when I used photoshop or played a 1080p video. I was using my laptop for almost 3 hours when i decided to use photoshop. It froze as soon as it started and made my screen display weird pixels. I restarted and tried to open photoshop again and this time, it froze. I did it the third time and after using PS for a minute, it did the split screen. After restarting yet again, I tried to play a 1080p video to just test my laptop. It froze as soon as VLC started. But when i only surf the web (which is the only thing I did before using PS), everything goes well. So I guess it really is the GPU and not the logic board or some other parts. I've decided to just have my laptop checked.

  • How to make Runtime.exec call Linux exec?

    Howdy,
    I am trying to use a combination of 'find' and 'rm' to delete all files with a certain extension in a directory and all of its subdirs.
    Here's the command:
    Process proc = runtime.exec("find " + dir + " -name '*.vcs' -exec rm -rf {} \\;");
    It's failing, not sure why, the exitCode is 1 instead of 0. I'm not sure if it's because I have to escape the '\' character, or if it's because I am calling Linux's 'exec' function within a Java exec() call, or something else entirely.
    The easiest thing to do would be to just use rm, but that doesn't seem to be an option. With rm it seems to be all or nothing -- If I try:
    rm -rf *.vcs
    it fails if it doesn't find a file with that extension in the start directory (even though I've specified -r). But if I enter:
    rm -rf *
    it nukes my directories AND files, something I don't want to happen. I realize this is a Linux thing, I'm just explaining it here as background, just in case.
    Anyway, so is there a way to do this? Perhaps with another system call, without using Linux's exec()?
    Many thanks
    Bob

    import java.io.*;
    public class ExecutingALinuxCommand
        static class PipeInputStreamToOutputStream implements Runnable
            PipeInputStreamToOutputStream(InputStream is, OutputStream os)
                is_ = is;
                os_ = os;
            public void run()
                try
                    byte[] buffer = new byte[1024];
                    for(int count = 0; (count = is_.read(buffer)) >= 0;)
                        os_.write(buffer, 0, count);
                catch (IOException e)
                    e.printStackTrace();
            private final InputStream is_;
            private final OutputStream os_;
        public static void main(String[] args)
            try
                String dir = System.getProperty("user.home") + "/work/dev";
                String[] command = {"sh","-c", "find " + dir + " -name '*.java' -exec grep -l Runtime {} \\;"};
                final Process process = Runtime.getRuntime().exec(command);
                new Thread(new PipeInputStreamToOutputStream(process.getInputStream(), System.out)).start();
                new Thread(new PipeInputStreamToOutputStream(process.getErrorStream(), System.err)).start();
                int returnCode = process.waitFor();
                System.out.println("Return code = " + returnCode);
            catch (Exception e)
                e.printStackTrace();
    }

Maybe you are looking for

  • How do I separate the pages in a two-page spread?

    I am using an InDesign document I created a couple of years ago as a template to build a similar 50 page 11x17 (8.5x11 folded) document. While I like working with the two-page spread on my big display, I don't have a printer that prints 11x17, so I w

  • Radio Button and Check Box

    I am looking for a way to implement a column domain as a radio button (e.g. Yes or No). So far I have only seen JHeadstart generate a list box. I cannot find any reference to radio buttons in the User Guide. Is it possible to generate a radio button?

  • How can I copy property nodes without them unlinking?

    I'm in the process of designing a VI that allows the user to choose between two methods of data analysis, each with a unique display structure. So I set up the two display methods, and overlapped them, and wrote a quick sequence to make the appropria

  • Chat and vision

    I ordered a Skype 4088 IP phone from your associate company Chat and Vision. As proof this is my receipt number: SO***. Today is now the 04/01/2013. The product was ordered and paid for on the 11/11/2012. I am still not in receipt of my order. I have

  • Global variable for function in JSP?

    Hi, In my JSP file I have a variable (sName) which I would like to use in a function. Is that possible? Do I have to declare it differently? Many thanks Simone Here the code fragement: <jsp:useBean id="s" class="ServiceRegistryClient"></jsp:useBean>