How to launch executable from a java program

In c++ we can use a function WinExec to execute exe from a c++ program.
Is there a way to launch executables using java program. Lets say I have one executable with name "myexecutable.exe" and a java program "myprogram.java". How can I launch "myexecutable.exe" from the java program.
Is there a way to do this in Java?
Vijay

>>
class LoadExecutable
static void loadProcess()
Runtime r = Runtime.getRuntime();
Process p = r.exex("winword.exe");
public static void main(String args[])
loadProcess();
}Regards
- ManikantanBoth of these aren't good ideas - neither of them
deals with the input or output streams at all.
Everyone who's posted to this thread should read this.
None of you knows how to use Runtime.exec properly:
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-t
aps.html
MOD
Thanks for the tips
-Regards
Manikantan

Similar Messages

  • Launching JNLP from a Java Program

    Hi All,
    Can anyone please let me know if I can launch a JNLP from a java program. The requirement is that there are two applications and I need to integrate both of them. So I need to call the other program from this. Can this be accomplished.
    Thank you,
    Thanks and Regards
    Mouli

    [Desktop.browse(jnlpUri)|http://java.sun.com/javase/6/docs/api/java/awt/Desktop.html#browse(java.net.URI)]

  • Calling an executable from a java program

    How can I call a compiled program from a java program. I have a fortran program, which I would like to call for execution from within my java program. My OS is linux.
    Thanks,
    An

    Not quite sure in the case of fortran program, but one thing can be done, call ur fortran program from a batch (.bat file) and call this .bat file from java ;
    try {
    Process p = Runtime.getRuntime().exec("run.bat");
    p.waitFor();
    catch( Exception e ) {
    }

  • Help Me! How to send sms from a java program with a pda connected to system

    help me ,
    I am new in JavaME. I have to send sms from a java program, A PDA is connect to the system. Can some one help me to make that program which interact with PDA connected to system and send sms to any mobile or pda phones.

    user12873853 wrote:
    I believe JavaMail API will help in sending the mails and SMS through SMTP server. Sounds more like false hope than belief to me. The only way that would work is if you have an SMS gateway that allows communication through SMTP. Doubtlessly some exist (searching for 'JavaMail sms' through google certainly seems to indicate this), but if you have to ask you don't have one.
    And that exactly where you are stuck: to send SMS messages you need an SMS gateway. That will be the first thing you have to shop for, until then there is no reason to think about code, protocols or implementations. It can be as simple as hooking up a mobile phone, but then you cannot send bulk messages of course. Most likely you'll need to shop around for a partner that has an SMS blasting service you can use.

  • How to invoke Netscape from a java program

    Hello
    In my Java program, I would like to launch a Netscape with one file as parameter in order to see the file with Netscape. Is there someone who can tell me how to do that, thanks.
    danfei

    System.getRuntime().exec("fullPathToNetscape/netscape parameter");

  • Execute several UNIX OS commands from inside Java program

    Greetings,
    I would like to be able to execute from a Java program several of the following UNIX commands
    script filename
    cd
    date
    grep
    diff
    I have been able to get a single command to work with
    Runtime rt = Runtime.getRuntime();
    Process p = rt.exec("dir");
    My goal here is to accomplish a Java program which will use JDBC to access an Oracle database with SQL and then compare the resultant flat file with a diff command in Unix to another delimited file from an Excel spreadsheet. Your input is appreciated.
    Thank you

    I would suggeat to use JDBC to get the data from database and then read your file and then use existing java diff program from following link to find the differences between the files
    http://www.bmsi.com/java/
    I hope this helps
    VAN

  • Calling servlet from a java program

    Hi
    I need to call a servlet's doPost() method from a java program. I have a specific situation, where I need to call servlet from a java program. DUring this call I need to pass a file and two string to the servlet. Servelt after receiving the file and string uploads the file to the server at a specified location. I am stuck up as how to call servlet from a java program instead of a HTML or JSP.
    Can anyone help me to start with this.
    any suggestion is welcome.

    You have to establish a URLConnection with servlet from your java program.
    URL servletURL = new URL("http://localhost:8080/Myservlet?str1=abc&str2=def");
    URLConnection servletConnection = servletURL.openConnection();you can get the objectOutputStream
    ObjectOutputStream oos = new ObjectOutputStream (servletConnection.getOutputStream());
    oos.writeObject(your file object);-------------------------------------------------
    In the servlet u can get the strings using request.getParameter("str1");
    In the servlet u can get the strings using request.getParameter("str2");
    file = new ObjectInputStream (request.getInputStream()).readObject()a lot of resources are available on this ...
    hope this helps :)

  • How to execute unix command from the Java program running on Windows

    Hello,
    I need to
    1. Execute a unix shell script from a Java program running on the Windows.
    2. I also need to capture the output of this shell script in my program.
    Please suggest me how to achieve this.
    Thanks in Advance.

    Hi...
    Something is missing here
    If you want to execute a shell script in windows that not posible unless you find or develop a unix shell script parser for windows.
    But if you are trying the execute a unix shell script on a remote unix computer from your java program running on a windows platform you can do that by logging on to the UNIX terminal which is running on port 23 I think.
    You can test this using telnet tool on windows
    just type on command prompt
    telnet <ip of the unix pc> <port number this case 23>
    you should get the unix terminal. If that works you can do the same through java or you can directly conect to port 23 of that pc using sockets that way your program will be platform independant

  • How can I execute a batch file from my java program

    Hi,
    Can someone help me or direct me to a link,
    How can I execute a DOS batch file from my java program?
    Thanks

    You will need to grab a handle to the process's
    outputstream so u can see its output.The OP didn't mention any output from any batch file;
    nor any input for that
    matter,so lets not complicate matters here for now
    ok?Actually I think this is essential to see whether it works or not. It's either that or do some manual check to see whether it ran, which is not exactly elegant, and in some cases this may not be easier than simply writing the output stream code, or in fact it may be impossible to check manually.
    I'm sure it wasn't intentional that your post appeared to be bristling with attitude.

  • How to start an executable program from a java program ?

    Hi,
    does someone know how to start an executable program from a JAVA program ?
    Thanks, Fred.

    Take a look at the Runtime class.
    -S-

  • How:Execute OS commands from a Java program

    hi,
    is it possible to execute an OS command from a java program, as in C/C++? if yes, plz give the details.
    thanx

    In the future try searching the forum before posting. Using keywords like "execute os commands" would lead you to several postings on this topic.
    Note the keywords where taken directly from you subject line. With practice you learn which keywords to use to yield the best search results.

  • How to run a cygwin.bat from a java program?

    Can you please let me know how to run a cygwin.bat file from a java program and to give commands through java program. I have a program to run .exe files, but when I do the same for the cygwin.bat it doesnt work. In task mgr a BASH and a cmd.exe is running. Please help me on this & bit urgent. Thanks in advance!

    Can you please let me know how to run a cygwin.bat
    file from a java program and to give commands through
    java program. I have a program to run .exe files, but
    when I do the same for the cygwin.bat it doesnt work.Of course not. .bat files are no native executables. You need to open a shell first, like "cmd /c cygwin.bat ..."
    & bit urgent. Thanks in advance!If I had read this earlier I wouldn't have replied. Why exactly is your time worth more than anybody else's?

  • Need to execute tcl script from a Java Program

    Hello,
    I need to execute a tcl script from a Java Program. But I do not know how to call the tcl Interpreter. Can anybody help me?

    Iam using the exec command as follows:
    Process proc =
    rt.exec("C:/SpirentConnect/engines/tcl/8.3.4/windows/s
    ctcl.exe C:/Hello.tcl");
    But Hello.tcl is not executed.And does that exact string work on the command line?
    And what is the return code from running it?

  • How do I launch executable from PS prompt?

    Hello,
    Very basic question, if I launch powershell and I'm trying to launch executable from "system32" (which is in PATH:), how do I do that without specifying exact path to it (like you can do in "CMD.EXE")
    PS C:\Users\g> nesth.exe winhttp show proxy
    The term 'nesth.exe' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the s
    pelling of the name, or if a path was included, verify that the path is correct and try again.
    At line:1 char:10
    + nesth.exe <<<< winhttp show proxy
    + CategoryInfo : ObjectNotFound: (nesth.exe:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

    That should work fine unless netsh.exe is not in your path or not installed on your system.
    You also need to type the command correctly (no fat fingers):
    netsh.exe winhttp show proxy
    I hope this post has helped!

  • How can I pass system commands from a java program? Urgent!

    hi,
    I have been trying this out since a long time. How do I send system commands to command.com or cmd.exe from a java program and an output of the executed command back to the java application.
    If u have any idea, or have any information about the kind os application reply back.
    Thanks
    Deepa Datar

    This is the code which I tried, but it displays only the title of MS-DOS, something like " Microsoft Corp...etc ". But doesn't take any input, and the subprocess(cmd.exe) hangs.
    import java.io.*;
    public class cmddemo2
    public static void main(String arg[])
    try
    System.out.println("cmd");
    Process p=Runtime.getRuntime().exec("cmd.exe");
    DataInputStream din=new DataInputStream(p.getInputStream());
    DataOutputStream dout=new DataOutputStream(p.getOutputStream());
    System.out.println("after streams");
    String s;
    dout.writeChars("type cmddemo2.java");
    while((s=din.readLine())!="\n")
    System.out.println(s);
    dout.writeChars("dir");
    String s1;
    while((s1=din.readLine())!="\n")
    System.out.println(s1);
    System.out.println("over");
    catch(Exception e)
    { System.out.println("Exception : "+e);

Maybe you are looking for