Running an external program

I want to write a routine that runs an command line statement to run a simple VB program and then use the return value. I know I use java.lang.Runtime.exec to run it but how do I get the return value?

Well, the API says exec() returns a Process set, and the exitValue() method returns an int return value, so you should be able to go from there...is that what you were looking for?

Similar Messages

  • How can I run an external program without quitting Firefox?

    I want to run an external program from within Firefox, much as Outlook express is run from the email button. How do I set this up?
    Firefox doesn't import my Bookmarks from the listed html file. Any cure for this?

    I don't want to run the mail program, I want to run another program.
    Maxthon allows me to do this using External Tools. Does Firefox allow me to run other programs without leaving Firefox?
    2. Firefox allows me to load an html file which contains my bookmarks, but it doesn't load the bookmarks file. is there a solution?

  • How can I run an external program from a PLSQL procedure?

    Is there a package to run an external program from PLSQL? or is there another way to do that?
    thanks.

    here there is an example about how a PL/SQL procedure can
    work with an external C program.
    http://download-east.oracle.com/docs/cd/A87860_01/doc/appdev.817/a76936/dbms_pi2.htm#1003384
    Apart from that you have Java Stored Procedures option
    to carry out your task.
    Java Stored Procedures Developer's Guide Contents / Search / Index / PDF
    http://download-east.oracle.com/docs/cd/B10501_01/java.920/a96659.pdf
    Joel P�rez

  • I need to run multiple external programs concurrently using RMI objects.

    have a web based solutiion which uses a backend machine for some processing. I have a RMI based Java proram running on the backend machine and the web server talks with this backend machine through RMI. Now, on this backend machine, I need to call some external program using Process s = Runtime.getRuntime().exec(....). Since this is a web application, multiple clients will connect at the same time and I need to run this external program for multiple clients at the same time.
    Here is what I do. I have a separate RMI object bound to registry for each client that connects to the web server. This RMI object implements runnable interface, since I can't extend this class from Thread (it already extends from UnicastRemoteObject). So each time I call upon a method from this object, only one process gets started and other objects need to wait till this process finishes.
    I need to start multiple processes at the sametime so that other clients don't have to wait for this thread to finish.
    Please let me know if anybody has any other solution than installing an application server on this backend machine.
    Here is my code.
    public class iLinkOnlineSession extends UnicastRemoteObject implements Session, Serializable, Runnable
      public iLinkOnlineSession(String sessName, String sessId, String rootLogs, String rootWrks) throws RemoteException
        setSessionId(sessId);
        setName(sessName);
        ROOT_LOGS = rootLogs;
        ROOT_WORKSPACE = rootWrks;
        searchKeys_ = new Vector();
        searchObjects_ = new Hashtable();
        Thread s = new Thread(this);
        s.start();
      public void run()
        System.out.println("running");
      public String checkLogin(String user, String passwd)
        String msg = "";
        String cmd = "iLinkOnlineLogin";
        cmd += " param "+ user + " param " + passwd;
        System.out.println("cmd: " + cmd);
        try
          Runtime run = Runtime.getRuntime();
          Process proc = run.exec(cmd);           // Call to the external program.
          InputStream in = proc.getInputStream();
          Reader inp = new InputStreamReader(in);
          BufferedReader rd = new BufferedReader(inp);
          String line = rd.readLine();
          while(line != null)
            System.out.println(line);
            msg += line;
            line = rd.readLine();       
          int res = proc.waitFor();
        }catch(Exception e)
             e.printStackTrace();
        System.out.println("Msg: " + msg);
        return msg;
      public String searchObject(String user, String passwd, String param1, String paramVal1, String param2, String paramVal2, String param3, String paramVal3, String relLev, String mfgLoc)
        String cmd = "iLinkOnlineSearch";
        cmd += " param " + user + " param " + passwd + " param " + getSessionId() + " param " + logFile_ + " param " + param1 + " param " + paramVal1 +
              " param " + param2 + " param " + paramVal2 + " param " + param3 + " param " + paramVal3 + " param "
              + relLev + " param " + mfgLoc;
        System.out.println("cmd: " + cmd);
        try
          Runtime run = Runtime.getRuntime();
          Process proc = run.exec(cmd);                // External program.
          InputStream in = proc.getInputStream();
          Reader inp = new InputStreamReader(in);
          BufferedReader rd = new BufferedReader(inp);
          FileWriter out = new FileWriter(resultFile_);
          System.out.println("Filename: "+resultFile_);
          BufferedWriter wout = new BufferedWriter(out);
          String line = rd.readLine();
           while(line != null)
            System.out.println(line);
            wout.write(line);
            wout.newLine();
            wout.flush();
            line = rd.readLine();
          int res = proc.waitFor();
          wout.close();
          if(res == 0)
            boolean ret = createResultTable();
            if(ret == true)
              return GlobalConstants.SUCCESS_MSG;
            else
              return GlobalConstants.ERROR_MSG;
        }catch(Exception e)
                e.printStackTrace();
        System.out.println("getting results");
        return GlobalConstants.ERROR_MSG;
      }

    I guess I don't get it.
    RMI servers are inherently multi-threaded, so why are you running separate servers for every client?

  • Running an External Program from Batch on Windows Server 2008R2 Failing

    Hi,
    I am trying to run an external program from a batch job and it is failing with this error message:
    Ext. prog.: ERROR: Input redirection is not supported, exiting the process immediately.
    Ext. prog.: External program terminated with exit code 1
    The program I am trying to run is:  timeout
    This command works on the OS: timeout -t 30
    I have setup the step to look like this:
    Under External Program:
    -Name: timeout
    -Parameter: -t 30
    I have also tried:
    -Name: timeout -t -30
    -Parameter:
    I am running ECC 6.04 on top of Windows Server 2008R2 with SQL Server 2008R2. 
    When we were running in Server 2003 on ECC 6.0 I was able to use the Sleep program just fine in the same manner.  I have found out that sleep is not available in server 2008.  It was replaced with timeout.
    After an update to EHP4 and moving to Windows Server 2008R2, Is there any pre-work that needs to be done on the SAP or Windows side before we can run external programs?
    Thank you,
    Neil

    > SAPService<SID> and <SID>ADM both have Administrator rights for the server.
    > That means they should have full access.
    No - this is no more true like that since Windows 2008, it's a bit more complex:
    http://en.wikipedia.org/wiki/User_Account_Control
    > Where would you setup the permission/policy to "interact with the desktop"?
    Add the policy using group policy editor (gpedit.msc)
    Markus

  • Running the external programs from SM69 t-code and RSBDCOS0 report

    Hi All,
      I am trying to execute the external commands from SM69 and RSBDCOS0. It's throwing the below error:
    26.10.2009 17:26:49 Job started                                                                                00           516
    26.10.2009 17:26:50 Step 001 started                                                                                BT           611
    26.10.2009 17:26:50 External command: ZARCHIVELOG_COPY                                                                BT           630
    26.10.2009 17:26:50 Related parameter:                                                                                BT           613
    26.10.2009 17:26:50 Ext. prog.:   > Function: BtcXpgPanicCan't exec external program (No such file or directory)      BT      606
    26.10.2009 17:26:50 Ext. prog.: External program terminated with exit code 1                                          BT           606
    26.10.2009 17:26:50 Ext. prog.: SAPXPG started on <hostname>_<SID>_00, Process ID 1632, Process Number 12   BT           606
    26.10.2009 17:26:50 External program was cancelled                                                                    BT           614
    26.10.2009 17:26:50 Job cancelled                                                                                00           518
    <SID>adm has full authorization on sapxpg.
    Please let me know what might be the wrong.
    Regards,
    Sridhar

    Dear Markus,
       The dev_xpg file contains the below information
    Trace file of external program (trace level 3)
    < Function: BtcTrcInit> Function: BtcXpgStart  External program: mv
      Process id: 29450
      Parent process id: 29449
      Rearrange StdErr to be collected in memory
      Rearrange StdOut to be collected in memory
    In t-code sm21 dont have any thing.
    Regards,
    sridhar

  • Running an external program from a JSP

    Can anyone help me? I have the following code which works for simple commands such as "ls ./dirname " but not for larger programs. The code works with programs such as FASTA and BLAST in standalone Java programs, but not in a JSP.
    String s = "Path of program to be run";
    Runtime rs = Runtime.getRuntime();
    Process p = rs.exec(s);
    p.waitFor();
    BufferedReader stdout = new BufferedReader(new InputStreamReader(p.getInputStream()));
    while((s = stdout.readLine()) != null){
       out.print(s);
    }Any advice would be greatly appreciated.
    Cheers,
    Tom

    woawow: this one is really scary! starting applications from a JSP!!
    don't you have another integration option? i wonder how thread safe is this approach... you try starting a new thread for this operation ?

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

  • AIR 2.6: Run external programs sequential (1 by 1)?

    Hi,
    I managed to run an external program in Adobe AIR (2.6). I'm using the NativeProcess for this. I would like to perform the following actions.
    Pseudo-code:
    execute program.exe
    this will return a port number
    set the port number as an environment variable (in windows)
    execute program.exe with several queries
    stop progam.exe
    The corresponding executables:
    C:\my_proj\program.exe start
    var portnumber:String = process.standardOutput.readUTFBytes(process.standardOutput.bytesAvailable);
    C:\WINDOWS\system32\cmd /c set port=portnumber
    C:\my_proj\program.exe query test1
    C:\my_proj\program.exe query test2
    C:\my_proj\program.exe stop
    My problem is the bold text in my source code underneath. I'm trying to wait till the first native process is finished and had returned its output. Once I have this output (=the portnumber) I can continue with the following action. And this is needed for all steps ... to execute them one by one.
    But "do {} while (process.running);" is not working. My AIR applications is getting stuck in this loop ... as if process.running is always true.
    Any idea how I can execute external programs sequential?
    This is my source code:
                var file:File = File.applicationDirectory;
                file = file.resolvePath("NativeApps");
                if (Capabilities.os.toLowerCase().indexOf("win") > -1)
                    file = file.resolvePath("C:\\my_proj\\program.exe");
                var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
                nativeProcessStartupInfo.executable = file;
                var processArgs:Vector.<String> = new Vector.<String>();
                processArgs[0] = "start";
                nativeProcessStartupInfo.arguments = processArgs;
                nativeProcessStartupInfo.workingDirectory = File.documentsDirectory;
                var process:NativeProcess = new NativeProcess();
                process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData);
                process.addEventListener(ProgressEvent.STANDARD_ERROR_DATA, onErrorData);
                process.addEventListener(NativeProcessExitEvent.EXIT, onExit);
                process.addEventListener(IOErrorEvent.STANDARD_OUTPUT_IO_ERROR, onIOError);
                process.addEventListener(IOErrorEvent.STANDARD_ERROR_IO_ERROR, onIOError);
                process.start(nativeProcessStartupInfo);
                do {} while (process.running);
                file = file.resolvePath("NativeApps");
                file = file.resolvePath("C:\\WINDOWS\system32\\cmd");
                var nativeProcessStartupInfo2:NativeProcessStartupInfo = new NativeProcessStartupInfo();
                nativeProcessStartupInfo2.executable = file;
                processArgs[0] = "/c";
                processArgs[1] = "set";
                processArgs[2] = "port="+portnumber;
    public function onOutputData(event:ProgressEvent):void
                var process:NativeProcess = event.target as NativeProcess;
                var portnumber:String = process.standardOutput.readUTFBytes(process.standardOutput.bytesAvailable);
    public function onExit(event:NativeProcessExitEvent):void
                process.exit();

    Hello,
    The  "do {} while (process.running);" may take almost all of the resource, so other code was blocked, then the program seems no response.
    You can add the following code in the onOutputData, like:
    public function onOutputData(event:ProgressEvent):void
        var process:NativeProcess = event.target as NativeProcess;
        var portnumber:String = process.standardOutput.readUTFBytes(process.standardOutput.bytesAvail able);
        file = file.resolvePath("NativeApps");
        file = file.resolvePath("C:\\WINDOWS\system32\\cmd");
        var nativeProcessStartupInfo2:NativeProcessStartupInfo = new NativeProcessStartupInfo();
        nativeProcessStartupInfo2.executable = file;
        processArgs[0] = "/c";
        processArgs[1] = "set";
        processArgs[2] = "port="+portnumber;

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

  • Manipulating an external Program

    Hi all,
    I know that we can run an external program in java with the command,
    Runtime.getRuntime().exec("pathname");
    and this returns to a precess. But is there a way to control that program over java. Such as not only opening internet explorer with java but also writing www.google.com on the search panel and hitting go. Is it possible and if yes how?
    Thanks in advance...

    There is a library of VIs on the web that allows LabVIEW to make several cool Windows API calls. One of the VIs will quit applications. On the home page, www.ni.com, enter windows api function 32 in the search window. It should be the second hit. The full title follow: Windows API Function Utilities (32-bit) for LabVIEW
    Jeremy Braden
    National Instruments

  • Load external program using labview

    Hi, i want to be able to run an external program e.g. a calibration routine using some other software. Then close the sequence i run in the external program, then run another sequence. Whats the best way of doing this?
    Stu

    Are you trying to invoke this program and then interact with it like a user would and then continue on with your program?
    You would need to know if this other application has some type of machine interface (API). It would be very difficult if not impossible to simulate a user to control the application through its UI. How does this application normally run? Does it support ActiveX? If so, you can interact with it that way. You would have to know the specifics of whatever interface it provides. Without that information I am not sure we could really give you any other suggestions.
    Mark Yedinak
    "Does anyone know where the love of God goes when the waves turn the minutes to hours?"
    Wreck of the Edmund Fitzgerald - Gordon Lightfoot

  • How to find out if an external program is running

    I am using LabVIEW 8.6 and have some vis that start an external program using the System Exec call. The program that is being started was not written by me, and I have no control over it. I need to make sure that it is started before I proceed, but I don't want it started more than once. At the moment I need to terminate it manually when I exit the vi. I also need to make sure that it is not running when I start the vi or I will get two copies. I have a switch to prevent  this, but it requires manual inspection and control every time I start the vi. I would like to know if there is some way the vi can list all the programs running and start the external program only when necessary. Closing it at the end would also be nice, but not as important as starting it once and only once. If I had control over the program I could use the existence of a file to tell me if the program is running or not, but that isn't possible. Is there some tricky way to use stdout in the System Exec call to accomplish the same thing?
    Rich

    Nothing tricky about it. Just use the command appopriate for your OS. For Windows:
    Then just use the Match Pattern function (for example) to search the string. 
    Message Edited by smercurio_fc on 03-02-2009 01:52 PM
    Attachments:
    Example_VI_BD.png ‏1 KB

  • Running External Program

    Hi All
    I really hope that some one can help ,e with my problem as i have no idea. OK i am calling an external program that outputs documents. This program uses control files and for each job there are 5 control files. Thus i call this program 5 times to get all my output documents. When i run this program from the command line then it works fine, however when i call it from my code i can see that it is working because my outputs are processed and i can see the program in the task manager. But it stops and does not continue to the next call, its like after this program does the processing then it just hangs. I dont know what is wrong and i cant get any errors in the logs either. I think that the problem either is with my java instalation as i had problems on the server and had to re-install java because someone installed multiple versions or that it is a jvm problem. Can some one please give some ideas of what could be the problem. My code looks as follow:
    Process p = Runtime.getRuntime().exec("d://cep//nt_engine_010_62 prodengine -controlfile=d://cep//document1.txt");
    p.waitFor();
    System.out.println(p.exitValue());

    You may want to give this code a try:
    ProcessBuilder pb = new ProcessBuilder( whatever_command );
          pb.redirectErrorStream();
          Process p = pb.start();
          InputStream is = p.getInputStream();
          BufferedReader br= new BufferedReader( new InputStreamReader( is ) );
          for ( String line = br.readLine(); line != null; line = br.readLine() )
            System.out.println( line );
          p.waitFor();

  • Leaving external program running and closing my app.

    Hello,
    I'm calling an external program from my java code and that program takes about 1hr to end its tasks so i want to en my calling program meanwhile.
    Is there a way to do this?
    thanks in advance!

    - I dont really understand what you need.
    Sorry I mean: I want to enD my calling program meanwhile
    - to close the java app and leave the another app running?
    My caller program is a console based program
    The program to be called is started by .sh script in unix/.bat in windows
    The caller program performs the call to the second and the second program is started but the problem is the caller program never ends, it just waits to the called program ends its tasks and then it ends. I dont want this.
    I want the second program be started and the caller program can ends without taking care in which moment the second program ends, of course in automatic way, with no final user ending the caller program.

Maybe you are looking for