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

Similar Messages

  • Executing external program (non-java)

    Hello,
    I just started programming Java. I installed SunForum3.2 on SunRay some days ago and I was faced with the problem that all that the people who are registered with the GateKeeper-Software are not shown anywhere. So I developed a small app, that read out a file containing the output of the command "registrar -q" ( displays all registered users including their SunForum-name ). Now some people not working on the SunRay-platform would like to connect as well to the SunForum-users. For this reason I'd like to execute "registrar -q" periodically and directly use the output from and within a Java-app but I couldn't find a way to execute the program "registrar -q" so far.
    Thanks for your help.
    Thomas

    Process p = Runtime.getRuntime().exec( "registrar -q" );
    Then read the Process's input stream, which should give you the stdout of your command. There are plenty of full code examples of how to do this floating about, and you should have no problem with it.

  • Pocket PC -Problem executing external program from java

    Hi,
    I'm developing an application on Dell Axim x51 PDA. I am using mysaifu jvm. The application needs to execute an external program (.exe) for which I'm using the Runtime class.
    I get java.io.IOException: The system cannot find the file specified.
    I have verified that the file exists. ( i used File class to check if the file exists)
    here's the part of code :
    Runtime rt = Runtime.getRuntime ();      
    File sktScan = new File("\\My Documents\\RFID\\ScktScan.exe");
    if(sktScan.exists())
    System.out.println("FILE EXISTS");
    String command = sktScan.getAbsolutePath();
    process = rt.exec (command);
    System.out.println("Socket Scan Path is : "+command);

    You have acces to "java.lang.Runtime currentRuntime.exec()" method ? in my case NetBeans IDE dont give me for my compilation with :
              microedition.configuration     CLDC-1.1     
              microedition.profiles     MIDP-2.0

  • Execute external program from java in the same virtual machine

    hello,
    I need some help. here is what i need: i'm developing a test tool and i need to execute the application to be tested from my test tool in the same virtual machine so that i can be able to connect to that application and catch events like clicking and so on.
    problem is that i do not know how to launch the application i want to test in the same virtual machine as the test tool.
    any help would be good,
    thanks

    problem is that i do not know how to launch the
    application i want to test in the same virtual
    machine as the test tool.Just invoke the main class of that application.
    You probably don't want to hear this, but writing a test tool is not easy if you are going to try to catch events etc. It's probably a bit too hard for you if you don't know how to invoke an app within the same VM.
    Kaj

  • How to call external files from java?

    How to call external files in java. For example how to call a *.pdf file to open in its default editor(say Acrobat), or a *.html file to open in the default browser or a *.txt file in a notepad etc..,
    In my program i have *.chm (Compiled Windows HTML Help) help file. how to open it in its default editor it?

    Jayarathina_Madharasan wrote:
    no one answered my questionHi what wrong did i do...basically insulted all the volunteers here who took the time to consider your question and try to offer you help. Other than that, you did nothing wrong.
    From JavaRanch :
    And even if an answer doesn't solve your problem, even if it should totally miss the point - the best thing to do to motivate others to continue trying to help you is showing respect and gratitude for the investment of time that was put into dealing with your issue.
    Edited by: Encephalopathic on Apr 14, 2008 10:01 AM

  • How to close external programs?

    Hi there,
    in vbs is a command "ExtProgram(ExtProgramName, ExtProgramArg)" to
    start external programs. But how to  close external programs when
    they finished its work? Is there a vbs-command for it? Is there a way
    when calling "cmd.exe" with a proper parameter?
    Martin Bohm

    Hello Martin!
    Yes, with the tool 'tasklist' in the same directory.
    The problem is that it is not easy to query from script. I tried it in the following script. Perhaps not perfect espacially because a command interpreter pop up every time you call the function.Option Explicit
    If IsDIAdemRunning() Then
    Call MsgBox( "At least one DIAdem is running!" )
    Else
    Call MsgBox( "No DIAdem at all!" )
    End If
    Function IsDIAdemRunning()
    Dim oWshShell
    Dim oExec
    ' Execute via Shell Object
    Set oWshShell = CreateObject("WScript.Shell")
    Set oExec = oWshShell.Exec( "C:\windows\system32\tasklist.exe /FI ""IMAGENAME eq DIAdem.exe""")
    ' wait until tasklist is finished
    Do While oExec.Status = 0
    Pause(1)
    Loop
    ' no Standard Output -> no DIAdem running
    IsDIAdemRunning = Len(oExec.StdOut.ReadAll) <> 0
    End Function
    A better solution might be possible via WMI.
    Matthias
    Matthias Alleweldt
    Project Engineer / Projektingenieur
    Twigeater?  

  • Executing external programs from PL/SQL?

    Hi All,
    Is it possible to execute external
    programs (i.e. shell scripts, or
    perl scripts) from a stored procedure
    or trigger?
    I know that typically it is the other
    way around, but hey try telling that
    to my boss.
    Thanks

    you cant execute any operating system commands from plsql
    procedures. but you can achieve result by using either java
    stored procedure or pro*C program .
    Suresh Vemulapalli

  • How to execute Linux command from Java app.

    Hi all,
    Could anyone show me how to execute Linux command from Java app. For example, I have the need to execute the "ls" command from my Java app (which is running on the Linux machine), how should I write the codes?
    Thanks a lot,

    You can use "built-in" shell commands, you just need to invoke the shell and tell it to run the command. See the -c switch in the man page for your shell. But, "ls" isn't built-in anyays.
    If you use exec, you will want to set the directory with the dir argument to exec, or add it to the command or cmdarray. See the API for the variants of java.lang.Runtime.exec(). (If you're invoking it repeatedly, you can most likely modify a cmdarray more efficiently than having exec() decompose your command).
    You will also definitely want to save the returned Process and read the output from it (possibly stderr too and get an exit status). See API for java.lang.Process. Here's an example
    java.io.BufferedReader br =
    new java.io.BufferedReader(new java.io.InputStreamReader(
    Runtime.getRuntime().exec ("/sbin/ifconfig ppp0").
    getInputStream()));
    while ((s = br.readLine()) != null) {...                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How to execute external exe in SSIS Package

    Hi,
    I wanted to know how to execute external exe from SSIS Package can any one explain me or provide me valuable links.
    Regards ,
    Ajay

    There are few things you need to take care before executing exe from SSIS
    1. The arguments etc expected by exe should be clearly defined inside execute process task
    2. The Path where exe exists should be accessible to the account executing the package. SO you should grant account required permissions
    3. If executing from a job make sure you either define a proxy account with required permissions and configure it to run the job or give service account all access required for executing exe
    see
    http://www.mssqltips.com/sqlservertip/2163/running-a-ssis-package-from-sql-server-agent-using-a-proxy-account/
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • 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)

  • How to call a external program in java?

    Help!!
    Is there any method that can a java program can call a external program? For example execute a exe file.
    Thanks.

    Yes.
    Runtime.getRuntime().exec("exactly what you would type at the command line");
    But be aware that this is operating-system-specific and full of gotchas. When you run into one of them, come back to the forum and do a search, this is a frequent topic of discussion.

  • How to call a external program in java program

    for example, if I want to execute internet explore or windows word in java program, how to do it?

    http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Runtime.html

  • How to execute dos command in Java program?

    In Perl, it has System(command) to call dos command.
    Does java have this thing?
    or any other way to execute dos command in java program?
    Because i must call javacto compile a file when the user inputed a java file name.

    Look in the Runtime class, it is implemented using the Singleton design pattern so you have to use the static method getRuntime to get its only instance, on that instance you can invoke methods like
    exec(String command) that will execute that command in a dos shell.
    Regards,
    Gerrit.

  • Executing external program

    My java application has a feature in which it executes an external program, which creates a file, then shuts down. That's working great.
    My problem: how can my program tell when the external program is finished executing, so that it can work with the created file?

    Basically you just need to call waitFor on the Process object returned from Runtime.exec. See this article for a more detailed discussion: http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

  • 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 ?

Maybe you are looking for

  • Navigation to coordinates with Ovi Maps v.3.04 on ...

    Is there some possibility to navigate towards coordinates instead of an address (street, town and s.o.)? Cell software version 50.0.005.502.02 Ovi Maps version 3.04 Could someone help me? Thanks & regards. Solved! Go to Solution.

  • Datacontrol complex return type binding to a table

    Hello guys can you please give a hand here? Here is the scenario: The return object of the method getAvailableConfigurations return a complex type AvailableConfigurationsDto and inside that object I need to access configuration Object that has the fo

  • BB10 OS problem after software update

    I purchased an unlocked STL-001 Z10 with 10.0.9 bundle 2372 from Dubai in March and have been currently using it in India over Bharti Airtel network. I started getting updates for the new OS 10.1.0.273 to be installed on my phone. I recently updated

  • Exporting Frames to BMP

    I'm working in flash with a small 100 frame movie. The application that I am using the "movie" for uses 100 frames in bmp format. As opposed to exporting individual frames, is there a way to export all 100 frames in sequential order named "0-100" res

  • PowerShell SCCM Set-ApplicationDeploymentType question

    I have a PS script moving files around and creating applications in the CM console. My problem is I have to be able to set custom return codes and I can't find a command that will allow me to do that. I also have to set deployment type requirements i