Running external program using java

hi
i am trying to run an external program using the runtime.exec() method. my problem is that the external program only runs when i press ctrl-c to exit my program. does anyone know how i can execute the external program while my program is still running without having to quit the program?should i be using threads?
thanks

As per the api doc exec will be executed as a seperate process
Process exec(String command) ------Executes the specified string command in a separate process.
Can you able to share that code what you have written ?

Similar Messages

  • Run external programs using runtime class

    Okay, I'm experiencing a really annoying problem with java.lang.runtime
    I'm building a GUI that needs to run some external programs, via a button say. These generally produce a text file or something, so I don't need to stream the output or anything (at least I'm assuming I don't?). Should be very simple...
    So at the terminal (bash) I would type ./programName , and everything will run hunkey dorey.
    In my code then, natrurally, I write
    String cmd = "./programName";
    Process p = runtime.getRuntime().exec(cmd);
    But low and behold...nothing happens. What is going on here, and how do I get around it! ??
    (On windows incidentally, it's no problem at all and works absolutely fine. But when I go over to mac, which is what I need to use, I'm screwed - only adding to the annoyance!)
    Any help would be much appreciated as I have a deadline looming!!

    You need to read the 4 sections of [http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html|http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html] and implement the recommendations. Failure to implement all the recommendations will cause you grief.
    P.S. The fragment of code you have posted shows that you have fallen for at least 4 of the traps.

  • Problems running external programs from java

    Hello.
    I wrote a pair of perl scripts and a GUI in java to run them. The first perl script just read the files in one directory makes some changes to the names of the files and then group all this files in a set of new directories. The other perl scripts takes all this new files and calls BLAST sequence alignment program and perform some alignments among these sequences. I tested this scripts and they work fine.
    The problem comes when I try to run them for the JAVA GUI. I use RunTime and when I need to run the first perl script it all works well, but when The call to the second perl script is made the program fisishes without doing anything at all. I found out that the problem is that when running the script from the Java GUI it's not able to find BLAST program. So I guess that Java is not really starting a terminal session and it doesn't read my bash_profile to find out the path to my programs.
    So, my question is if anyone knows a method to tell Java to load all this paths in the bash_proflie file so all of my scripts work???.
    I have no idea is this can be done and how so any advice would be really wellcome.
    By the way, my java version is 1.4.2 and my OS is Mac OS X 10.3
    Thanks a lot , Julio

    Invoke /bin/sh -c and give it your program's full path with.
    (To understand what I've written, maybe reading
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps_p.html
    http://mindprod.com/jgloss/exec.html
    and
    http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Runtime.html
    (especially the exec(String[] cmdarray) method)
    might help)
    -T-

  • Help! how to run other programs using java

    how can i run other programs or exe files using java, anyone can give sample codes for this.
    ex. if I click [run MsWord] button, then msWord automatically lunch

    RunTime.getRuntime().exec(string command)
    I guess, it might help you..java.lang.Runtime

  • How can I run other programs using java program

    hi experts,
    I am trying to execute a set of commands from java program
    eg: from command prompt
    java CommandExecutor c:\winnt\notepad.exe c:\some.exe c:\onemorecommand.exe
    and inside the CommandExecutor main method..
    public static void main(String []arg)
    for(i = 0; i < arg.length; i++)
    Runtime.getRuntime().exec(arg(i));
    the above code is executing all the command one after the other, but I want to execute the above commands squentially, i.e I want to execute the second command only after finishing the first command and the third after finishing the second and so on depending upon the arguments passed, how can I acheive this...
    I have tried to use the Process which is returned by the exec(arg) method but the exitValue() returns same value before execution and after execution.
    thanks,
    krishna

    Did you try to get the process returned and then try
    process.waitFor() method. This waits for the process to finish.
    After that try the next execution

  • Help with running external programs within java

    Hi,
    I'm new here, and not sure whether i'm in the right place for this, but i thought i'd give it a shot anyway!
    Basically i have a fortran program already written, that takes in the name of a text file as an input. I'm wanting to create a user interface to create this text file, and then i would have a button or something to enable me to then run the fortran program and input the file all from the user interface, and get rid of the need to manually run the fortran program.
    Firstly, is this even possible?! Is it difficult to program and get to work?! Does anyone have any suggestions or guidance on this.
    Thanks

    @Op.
    ..and here are two links related to that.
    http://java.sun.com/developer/JDCTechTips/2003/tt0304.html
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

  • Run External Program in Java

    I need to run a VB batch in a class Java.
    If someone can help me because I don't know the method.

    It's OK but if I don't export the result on the standard output, the run doesn't work.
    So I added this code :
    DataInputStream dis = new DataInputStream( newProcess.getInputStream() );
    String line;
    while( (line = dis.readLine()) != null )
    System.out.println(line);
    Have you got another solution to do it or an explication on this ?
    Thanks

  • New "Windows Programming Using Java" Website

    Our newly created "Windows Programming Using Java" website (http://fivedots.coe.psu.ac.th/~ad/winJava/) is for programmers who want to extend Java's capabilities on Windows XP and/or Vista, but aren't sure where to start. One of the drawbacks of Java's portability is that many Java programmers have a rather sketchy knowledge of Windows-specific programming.
    We plan to explain how Java applications can utilize Windows application software, OS features, and hardware beyond the reach of Java's standard libraries. A variety of Java/Windows programming techniques will be explained, including:
    * Java's employment of the Win32 API via C, JNI, and J/Invoke.
    * Java's utilization of Window's Command Line Interface (CLI) and batch files, accessed through Java's Runtime, ProcessBuilder, and Process classes.
    * Java and Windows object-based scripting, centered around the use of VBScript, Windows Script Host (WSH), and Windows Management Instrumentation (WMI).
    * Java interoperability with COM, including hosting of ActiveX controls in Swing containers using jacoZoom.
    This website is a work in progress, with four chapters available for download at the moment. We'll be adding more regularly, and would love feedback on what we're doing.
    Thanks,
    Gayathri Singh and Andrew Davison
    [email protected] and [email protected]
    Edited by: AndrewDavison on Jun 20, 2008 1:36 AM

    Hi, I am looking the similar kind of requirement that you had done.. Do you have any more details on the code that is working for you . All i need is if the user logs in successfully in windows, the the app should be accessible. Please let me know if you have the code with you on this problem.
    Thanks in advance
    "what i meant is the we b applications running in my system, when i access the application iam able to to login automatically with windows authentication and now in case of other users following process happened:"

  • How to run the program using specific classpath

    Recently I installed Javamail 1.2 and JAF1.0.1 on my NT Box and set up the classpath. I can compile my java email code by using: javac myEmail.java. But when I tried to run the code using java myEmail, it always gives the error: Exception in thread "main" java.lang.NoClassDefFoundError: myEmail.
    when I use -verbose and found that it always goes to:
    C:\Program Files\JavaSoft\JRE\1.3.1\lib\rt.jar to find classes even I use -cp option to point Javamail\mail.jar and activation.jar.
    what is wrong with it? Thank you in advance!!!!!!

    What does this have to do with JMS. I suggest that this should have been posted to the Java Programming forum where you would have gotten a quick response as this is a simple problem to diagnose.
    The problem is that the class myEmail, which you created, is not on the class path so it cannot find it. It has nothing to do with the location of mail.jar and activation.jar, although this may cause problems later.
    What you need to do is check the classpath in the environment variables section of the System dialog box. Make sure it refers to . (the current directory) as well as the locations of mail.jar and activation.jar. Also when you invoke myEmail ensure you are in the same directory.
    Hope this helps

  • Run external programs

    Hi there..
    I need a example to run others programs from Java, for example lunch the explorer.. Is possible do that?
    Thanks you

    Have a look at the Runtime class and especially the exec method. You should be able to do what you want using the following code:
    Runtime.getRuntime().exec("explorer");

  • How to execute external program in java?

    My question is how to execute an external program in java.
    I need to call a unix command in java.
    Thanks.

    it depends on what you are trying to do. Following are the two methods
    1. Runtime.exec() : this method allows you just to call an external program as a seperate process
    2. JNI (Native Interface) :- As of right now only C and C++ are supported by this method. This method allows you to directly call the C/C++ methods from JAVA

  • Can any one please send me sample programs using java mapping..

    <b>Can any one please send me sample programs using java mapping with input and output?</b>
    please let me know how to get started with java mapping?
    Prerequisites for java mapping ?
    What are the jars need to be deployed for SAX,DOM.  And how to do it in NWDS?
    Use of Execute() and setparameter() ... StreamTransformation?
    Some sample program using java mapping with simple logic(input and output)?

    Hi,
    Did you go thro these blogs?
    /people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-i
    /people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-ii
    /people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-iii
    Nice blogs to start Java Mapping.
    Go thro this one too.
    /people/stefan.grube/blog/2006/10/23/testing-and-debugging-java-mapping-in-developer-studio
    Regards,
    P.Venkat
    Message was edited by:
            Venkataramanan

  • Kernel programming using Java

    I'm currently doing a research in computer security and would like to develop a system which can deal directly to linux kernel in order to enhance the security. During my research I found that Java is a type-safe language which is more secure if I develop my system compare to C language which is lack of type-safe. So I decided to use Java to develop my security system which will enhance resources management in Linux. My question is, does anyone know whether Java could be used in kernel programming or not? Where could I get some sort of references related to my work especially tutorial about kernel programming using Java. I would appreciate if anyone of you could help me in this matter. TQ

    I'm currently doing a research in computer security ...You might want to do a bit more research into the languages.
    What you are discussing has nothing to do with security.
    If you are writing kernel services then java is probably ill suited because the normal implementations use garbage collection which is not under your control. This makes it hard (if not impossible) to control timing.
    If your sole desire is type safety then C++ provides better type safety and provides more control over types as well.

  • How to run native program with Java program?

    Hello
    I've got following problem. I'd like to write file browser which would work for Linux and
    Windows. Most of this program would be independent of the system but running programs not. How to run Linux program from Java program (or applet) and how to do it in Windows?.
    Cheers

    Try this:
    Runtime rt = Runtime.getRuntime();
    Process proc = rt.exec("ls -l");
    InputStream stream = proc.getInputStream();
    InputStreamReader isr = new InputStreamReader(stream);
    BufferedReader br = new BufferedReader(isr);
    String line = null;
    while ( (line = br.readLine()) != null) .....
    "if the program you launch produces output or expects input, ensure that you process the input and output streams" (http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html)

  • Mail Program using Java as...

    HI!
    Is this possible in java...
    to make Mail Program using Java as frontend & use Outlook Express database as backend
    PLease Help...
    Bunty India

    Hi Gandalf,
    I picked up your code and ran it, couple of things, firstly windows and Unix line terminations are different so in your method doCommand use "\r\n" not just \n, this will give a full <CRLF>
    On you initial HELO you want to use your computer's id as part of the command so use this line:
    sender_domain = InetAddress.getLocalHost().getHostName();
    String s1 = new String("HELO " + sender_domain);
    s1.trim();
    response = doCommand(s1);
    Cheers
    Dom

Maybe you are looking for

  • Lightroom doesn't export a raw file in Photoshop CS6

    I have both PhShP elements and CS6. I recently started working on an IMac. On my windows computer I always exported my files with Lightroom adjustments to CS6 and back. When I ask to export a file in CS6 with Lighroom ajustments it opens PhShP Elemen

  • Itunes 11.4 will not open

    I just updated my iMac (2.66 Ghz Intel, with 2GB memory, and 230 GB available HD space ) to 10.6.8 via System Preferences auto update. Along with the system update came iTunes 11.4. Now, when I click on the iTunes icon on the dock it bounces a few ti

  • In iTunes 10.7, some of my podcasts don't transfer to my iPhone.

       When I look in iTunes at the podcast list on my phone, the ones that don't transfer have a grey logo beside them (grey circle with two circular white arrows in them.)  I don't see any reason why they shouldn't transfer.  What's going on?   I can d

  • Xournal pdf exporting of lower quality

    I added some highlighting and text to the original pdf within the xournal. But the output quality of the original pdf changes (text with drawing), after exporting. Is there a way around. http://xournal.sourceforge.net/manual.html#printing states: "If

  • Best Location for Deploying Common File in WSP

    I have a small wsp containing a masterpage and a stylesheet that will act as the standard branding for many SP site collections in my company.  One of the requirements is to have a footer with a link to a Terms & Conditions PDF in the masterpage.  So