Trying to call a program within a Java application

Hi,
I am trying to call a program from within a Java application.
Here's my code:
// the program siftwin32 takes it's input via < and outputs using >
String command = "C:/Demo/siftDemoV4/siftDemoV4/siftWin32.exe < c:/demo/query.pgm >c:/demo/query.key";
Process p = Runtime.getRuntime().exec(command);
int val = p.waitFor();
The program "siftwin32" never executes. That is, the .key file is never generated. The value returned from the waitFor() is 1 which I know is bad.
I'm not sure what the problem is. Running siftwin32 from the command line works fine.
Any help would be greatly appreciated!
Thanks,
Neal
Edited by: nealchecka on Nov 28, 2007 10:01 PM

It's probably being executed; you're just passing it bad arguments and confusing it.
The < and > operators are something that the shell uses. They're not arguments to programs typically. When you run it from the command line, it's going through a shell (the command line is the shell, that is to say a program for running other programs).
When you run Runtime.exec, it doesn't go through the shell. The program is executed directly. If you use the version of exec() that takes a single string argument, the string is tokenized on whitespace and the tokens are used as the executable and its arguments.
You have a few options.
One is to write a shell script (or I guess a batch file on windows) that does the i/o redirection, and invoke that script.
Another can be to send all these arguments to the shell by passing them on the command line to the shell, or to "start" or something (I'm not sure about what Windows does specifically). You can find examples online.
Or you can do the redirection yourself, in the Java program. After you exec, use the resulting Process object to get the standard input, standard output, and standard error streams, and write/read/read those streams. If you like you can read from or write to files with those streams. Personally I generally prefer this option, since it has less dependency on the OS, and it's more flexible, and it's more tightly integrated into the Java class.

Similar Messages

  • How can native executable files be started from within a Java application.

    Hi Everyone,
    I am currently working on an application that will have the ability to start a program within Windows. What I intend on having is a button within my GUI that can start Microsoft Word. I am completely lost as to where I should begin in order to make this work. If anybody has any pointers they will be greatly appreciated. Thanks.
    Regards
    D

    Hi ,
    easy:
    Runtime.getRuntime().exec(new String[]{path,name});
    see:
    http://java.sun.com/j2se/1.3/docs/api/java/lang/Runtime.html
    HTH

  • Can we call a webservice  using standalone java application  ?

    Hi friends,
                   Can we call configurd webservice in xi , using standalone java application by just giving url of webservice ?
                  OR
                  Only by means of WEBDynapro we can call  ?
                    Can you please tell me the answer for this .
    Regards .,
    V.Rangarajan

    HI Ranga Rajan
    well, If at all if you have webservice...you can import that werbserivce as External definition in to IR.
    How to import:
    1) Go to IR and and move to your requied component and there you can see the option called imported objects...select on imported objects where you can give the name and you can select the webservices which you want to use it.
    2) Hope you are aware of that a werbservice will have the request and response.
    3) Create the mapping program accroding to your requirement.
    Go through blogs of Bhavesh and Naveen which talks about calling webservice in a specific condition:
    Webservice Calls From a User Defined Function - /people/bhavesh.kantilal/blog/2006/11/20/webservice-calls-from-a-user-defined-function
    Consuming/Calling webservices from DataBases - /people/sap.user72/blog/2005/10/20/consumingcalling-webservices-from-databases
    Also check this help file on Web Services:
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/336365d3-0401-0010-9884-a651295aeaa9
    Cheers..
    Vasu
    <i>** Reward Points if found useful **</i>

  • How can I execute an IE browser window from within my java application?

    I am programming a java application that requires me to execute a browser application and point to a specific web site. How can I do this? I cannot seem to find any examples on the web.

    Hi Heals,
    This forum is for discussing Measurement Studio for Visual Basic and is not really a good place to ask general purpose Java questions. I suggest searching one of the comp.lang.java.* newsgroups at http://groups.google.com/.
    Off the top of my head, though, I would say take a look at the Runtime.exec method.
    - Elton

  • Calling ABAP class methods from JAVA application

    Hi All,
    I want to fetch ITS related information (SITSPMON Tcode) in my JAVA application. But i didnt find much BAPIs for the same. While debugging I came accross few class methods with help of which I can get the required information. So is there any way we can call and execute methods of ABAP classes through java application?
    for e.g. I want to call GET_VERSION method of CL_ITSP_UTIL class.
    Thanks,
    Arati.

    Hi,
    Yes, as per my knowledge the only way to interact is using BAPI exposed as RFCs. So try to invoke those class methods in one CUSTOM BAPI and expose that BAPI as RFC and consume that RFC to get those details.
    Regards,
    Charan

  • Call c++ program .exe from java

    Hello every body
    i have a problem while calling Hello.exe from java
    c++ code
    #include "stdafx.h"
    #include <iostream>
    # include <string>
    using namespace std;
    int main(int argc, char *argv[])
         int x;
         cout<<"Just test ";
    return 0;
    }java code:
    import java.io.IOException;
    public class runtime{
        public static void main(String[] args){
        try
        Process process = Runtime.getRuntime().exec("Hello.exe");
        }catch (IOException e)
         e.printStackTrace();
    }it display nothing!!

    alexxzius wrote:
    String line="";
    BufferedReader input =
    new BufferedReader
    (new InputStreamReader(process.getInputStream()));
    while ((line = input.readLine()) != null) {
    System.out.println(line);
    There is a danger of deadlock in this code. The OP should 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 ALL the recommendations.

  • Compiling a program from a Java application

    Hello,
    I'm new to Java and i'm developing an application which takes in a Java source code (.java) and compiles (to create the '.class' file. However I dont know HOW i could use my Java program to compile the source code file.
    I did a google search and found out that there is a com.sun.tools.javac.Main.Compile method to compile the source code. When i put this line into my code and i compile it, it says:
    package com.sun.tools.javac.Main doesn't exist (assuming i need to have a package for it).
    Does anyone know how I can resolve this? or know any good useful references I can read on the web?
    note that i'm using Java 6.
    Any help would be good. Thanks.

    Hi,
    Note that your question was posted in the wong forum. It's not related to reflection.
    What you tried to use is JDK version dependent, you should instead use the new Compiler API that's available if you are using Java 6.
    [http://www.juixe.com/techknow/index.php/2006/12/13/java-se-6-compiler-api/]
    Kaj

  • Is it possible to call msync from within an EVB Application?

    Does anyone know how to run mSync from within an embedded visual basic application?
    Some sample code or documentation would be particularly welcome.

    The following is taken from the Windows CE documentation that ships with 9i Lite:
    Table 3-16 ISyncOption Public Properties
    username -> Name of the user.
    password -> User password.
    syncParam -> Synchronization preferences. See Section 3.7.2.4, "COM Interface SyncParam Settings" for more information.
    transportType -> Type of transport to use. Only "HTTP" type is supported currently. The default value is HTTP.
    transportParam Parameters of the transport. See Section 3.7.1.5, "Java Interface TransportParam Parameters" for more information.
    syncParam documentation is (also taken from the same document):
    The syncParam is a string that allows support parameters to be specified to the synchronization session. The string is constructed of name-and-value pairs, for example:
    "name=value;name2=value2;name3=value3, ...;"
    The names are not case sensitive, but the values are. The field names which can be used are listed in Table 3-17.
    Table 3-17 COM Interface SyncParam Settings
    "reset" -> N/A Clear all entries in the environment before applying any remaining settings.
    "security" -> "SSL" "CAST5" Use the appropriate selection to choose either SSL or CAST5 stream encryption.
    "pushonly" -> N/A Use this setting to upload changes from the client to the server only, download is not allowed.This is useful when data transfer is one way, client to server.
    "noapps" -> N/A Do not download any new or updated applications. This is useful when synchronizing over a slow connection or on a slow network.
    "syncDirection" -> "SendOnly" "ReceiveOnly" "SendOnly" is the same as "pushonly". "RecieveOnly" allows no changes to be posted to the server.
    "noNewPubs" -> N/A This setting prevents any new publications created since the last synchronization from being sent, and only synchronizes data from the current publications.
    "tableFlag [Publication.Item]" "enable" "disable" The "enable" setting allows [Publication.Item] to be synchronized, disable prevents synchronization.
    "fullrefresh" -> N/A Forces a complete refresh.
    "clientDBMode" -> "EMBEDDED" "CLIENT" If set to "EMBEDDED", access to the database is by conventional ODBC, if set to "CLIENT" access is by multi-client ODBC.
    Example 1
    The first example enables SSL security and disables application deployment for the current synchronization session:
    "security=SSL;noapps;"

  • HOw to call desktop icons to my java application

    Hi All,
    i want to call all desktop icons to my swing appliation
    pls tell me how to do this, very important for us.
    bye
    N.S

    So "we" have created several applications that want to
    replace task manager, explorer, and now call desktop
    icons? What are "we" writing?
    http://forum.java.sun.com/thread.jsp?thread=213683&foru
    =4&message=735627guys, why are you fucking around ? maybe the originator of this thread will have to rephrase the question (I agree on that), but there is no need to get nasty.

  • How to create a set up program for my Java application

    Can some one please tell how to create a Setup for my Java Application

    Thanks for your reply.
    But still if you could have answered my query it would have been of a little more help for me, as I am quite new to any of these kinds of forum.
    Still thanks a lot for the reply.

  • Re: Error using JMF within a Java Application

    I found the solution. I needed to add the DLLs included by JMF in the Windows\System32 folder to my application's classpath.
    For those who might not know, the DLLs are:
    windows\system32\jmacm.dll
    windows\system32\jmam.dll
    windows\system32\jmcvid.dll
    windows\system32\jmdaud.dll
    windows\system32\jmdaudc.dll
    windows\system32\jmddraw.dll
    windows\system32\jmfjawt.dll
    windows\system32\jmg723.dll
    windows\system32\jmgdi.dll
    windows\system32\jmgsm.dll
    windows\system32\jmh261.dll
    windows\system32\jmh263enc.dll
    windows\system32\jmjpeg.dll
    windows\system32\jmmci.dll
    windows\system32\jmmpa.dll
    windows\system32\jmmpegv.dll
    windows\system32\jmutil.dll
    windows\system32\jmvcm.dll
    windows\system32\jmvfw.dll
    windows\system32\jmvh263.dll
    windows\system32\jsound.dll
    Edited by: alvarocavalcanti on Jul 9, 2008 12:07 PM

    There's a way, take a look at the javax.swing API documentation.

  • Running a "heavy" program from within a java class

    Dear Java programmers,
    I 'm trying to run a software called surflex from within a java class, using the following java command:
    Runtime.getRuntime().exec( new String[ { "/bin/bash", "docking_script_2.bash"} );
    For convenience I've created the following simple bash script but for some strange reason surflex is not executed:
    #!/bin/bash
    surflex-dock-v211-linux.exe proto drug.mol2 receptor_hydro.mol2 p1;
    surflex-dock-v211-linux.exe dock drug.mol2 p1-protomol.mol2 receptor_hydro.mol2 >& 1OHR_A_output.txt;
    Can anybody help me on that (ignore the arguments, they are correctly set)? I'll try to find another, more generic example, but so far I've noticed that the same thing happens with unix grep command.
    thanks,
    Tom

    I think if you want to invoke a bash shell and give it a command to execute, you need to do
    /bin/bash -c commandrather than
    /bin/bash commandAccordingly, your call to exec should look like
    exec( new String[ { "/bin/bash", "-c" "docking_script_2.bash"} );Beyond, that, I'd suggest the following as general debugging tips and best practices:
    * As the first line of the bash script, include a line that does something simple, like touch a file, so you can see if the script is executing at all.
    * In Java, call Process.waitFor(). Its return value is the process' exit value.
    * Make sure you're gobbling stdout and stderr from the process, and giving stdin any input it needs. You'll have to do this for the process to run correctly, and you can also use what you read from stdout and stderr to debug the execution of the process. [http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html]
    * You may wan to look into ProcessBuilder, rather than Runtime.exec. I haven't used it myself yet, but apparently it's supposed to be the preferred way to execute external processes.

  • Calling oracle SQL Loader from java program

    Hi,
    I want to insert data into oracle tables from a text files containing fixed length fields. I am using SQLLoader to achieve this. The requirement is to call the SQLLoader within the java program.
    Does anyone know how to call SQL Loader from java program?
    Thanks,
    Varsha

    Simply "exec" the sqlldr program with the parameters you need to pass to it.
    Runtime.exec (........)
    Try to pass all parameters needed including the username and password, and use the option "silent" to avoid output, and the option "log" to have a log file of the modifications that sqlldr has done to the database.

  • Start a WS application from within a java program

    Hi,
    I need to start a WebStart application from within a java program. Therefore I develeoped a class which starts javaws.exe within its main-method like this:
    try {
    Runtime.getRuntime().exec(
    "c:\\java web start\\javaws.exe http://a.b/c.jnlp"
    } catch (Exception e) {
    e.printStackTrace();
    And that did not work. Java Web Start tries to start the .jnlp program but returns with the message, that the app-desc|applet-desc|installer-desc|component-desc is missing. But it is there: It is an applet and thus I defined an applet-dec.
    I tried to do it from a command line with the followinf command:
    java -Djnlpx.home="C:\abc" -cp "C:\abc\javaws.jar" com.sun.javaws.Main http://a.b/c.jnlp
    And that works. But using this command from within my jjava prog using the Runtime.exec() method does not work.
    By the way, simply type "javaws http://a.b/c.jnlp" at the command line does not work.
    Can anybody help me? How may I start a .jnlp program within another java program.
    Kind Regards,
    Tobias Neubert

    Hi,
    I recently had a quite similar problem. At least the error message by the Java Web Start application on Mac OS X complained about the same error (app-desc|applet-desc|installer-desc|component-desc). It turned out to be some bad invisible characters in the jnlp file. I copied some sample from a web page which for some reason contained some unicode chars that the parser doesn't like. Use a different text editor or the less command on unix to see if there are some strange characters in you jnlp file.
    But it seems strange that it does work from the command line and not from your code.
    -Stefan

  • Unable to call Java class method within Embedding Java Activity in BPEL

    Hi ,
    I have written Java Class named 'Class3' .
    When I am creating and trying to call these classes whithin Embedding Java Activity , compile time error is coming. Compiler is not finding class . Error message is like this one.
    uildfile: C:\Oracle\Middleware\jdeveloper\bin\ant-sca-compile.xml
    scac:
    [scac] Validating composite : 'C:\JDeveloper\mywork\Application7\Embedded15\composite.xml'
    [scac] C:\JDeveloper\mywork\Application7\Embedded15\SCA-INF\bpel\BPELEmbedded15\src\orabpel\bpelembedded15\ExecLetBxExe0.java:73: cannot find symbol
    [scac] symbol : class Class3
    [scac] location: class orabpel.bpelembedded15.ExecLetBxExe0
    [scac] C:\JDeveloper\mywork\Application7\Embedded15\SCA-INF\bpel\BPELEmbedded15\src\orabpel\bpelembedded15\ExecLetBxExe0.java:73: cannot find symbol
    [scac] symbol : class Class3
    [scac] location: class orabpel.bpelembedded15.ExecLetBxExe0
    [scac] Note: C:\JDeveloper\mywork\Application7\Embedded15\SCA-INF\bpel\BPELEmbedded15\src\orabpel\bpelembedded15\BPEL_BIN.java uses unchecked or unsafe operations.
    [scac] Note: Recompile with -Xlint:unchecked for details.
    [scac] FATAL_ERROR: location {ns:composite/ns:component[@name='BPELEmbedded15']}(20,36): Failed to compile bpel generated classes.
    [scac] failure to compile the generated BPEL classes for BPEL process "BPELEmbedded15" of composite "default/Embedded15!1.0"
    [scac] The class path setting is incorrect.
    [scac] Ensure that the class path is set correctly. If this happens on the server side, verify that the custom classes or jars which this BPEL process is depending on are deployed correctly. Also verify that the run time is using the same release/version.
    [scac]
    BUILD FAILED
    C:\Oracle\Middleware\jdeveloper\bin\ant-sca-compile.xml:264: Java returned: 1 Check log file : C:\JDeveloper\mywork\Application7\Embedded15\SCA-INF\classes\scac.log for errors
    Total time: 8 seconds
    I am creating Class3 directly in Application Resources folder indide Project Folder in Jdeveloper without creating any package. Code of the class is .......
    public class Class3 {
    public Class3() {
    super();
    public String getValue(){
    return "BBBBBBB";
    Can any one help?
    Regards
    Yogendra Rishishwar
    9867927087

    Hi ,
    In your java project frm jdev..right click and choose general and then choose deployment profiles and then choose Jar ..and then give some appropriate name(abc) and then click ok.
    Then under resources file u get a abc.deploy file right click and say deploy to jar ..u will find the jar in that director.Now include this jar in your prjct libraries.
    have a look at the link http://niallcblogs.blogspot.com/search/label/embedded%20Java

Maybe you are looking for

  • Slow BB, changed microfilter, how long does it tak...

    hello I have been getting about 12-15Mbit/s, but this has been getting worse over the last few months. I think it's a duff microfilter, I was seeing noise margin of about 20dB, but I swapped one of them and now it's showing 4.5dB, which I think is he

  • Song Pop doesn't load anymore.  Do I have to clean the cache?  If so, how do I do that?

    I have a Mac Book Pro.  I have been playing Song Pop for about 6 months.  However, just starting today, Song Pop doesn't load.  The record on the title page of Song Pop just keeps spinning.  I saw someplace online that I might have to clean the cache

  • Just got Mac Box Set & WD My Book Essential 1TB External Hard !!!

    I am excited & preparing for my upgrade from my 10.4.11 to 10.6.3 !!! Model Name: MacBook Model Identifier: MacBook2,1 Processor Name: Intel Core 2 Duo Processor Speed: 2.16 GHz Number Of Processors: 1 Total Number Of Cores: 2 L2 Cache (per processor

  • Oracle JDBC thin driver 10g exceptions

    Can anyone tell me where I can find more resources about exceptions what I should expect if one node in cluster fails. Let assume that I am using WebLogic server. Thanks,

  • Webcam with PC users with MSN?

    Hi, I'm wondering what application I can use to use my webcam and see the person Im talking with webcams and were both using hotmail. I love iChat but for people i know who use msn messenger for pc cannot use their webcams with me. thanks in a advanc