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

Similar Messages

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

  • Executing external programs in Windows from UNIX

    Hi all,
    I would like to call an external program in Windows box from UNIX box. I tried to create a command in SM69, specify the command and OS type to Windows. When I try to execute the command in SM49, I got an error 'program_start_error'.
    I tried also to create an RFC destination in SM59, using connection type = T (start external program via TCP/IP), specifying the program in the Program field and specify the Windows box hostname (or IP add) in the Target host. But this also seemed could not work.
    Is there any other ways I could do this?
    Thank you.
    Mizwan

    <b>RSBDCOS0 Execute UNIX commands. </b>
    Look at <b>SM69, SM49</b> and
    Function <b>SXPG_COMMAND_EXECUTE</b>
    e.g. SM69
    Press F5 or click Change button
    Press F6 or click Create
    Fill in the following parameter :-
    Command name                                        - the unix scripts file name e.g. ZABAPFTP
    Operating system command                       - e.g. sh
    Parameters for operating system command - e.g. /sap_production/usr/sap/trans/data/zabapftp.sh
    REPORT  ZABAPFTP.
    data : t_btcxpm      like btcxpm occurs 0,
             p_addparam like sxpgcolist-parameters,
             rep_date       like sy-datum,
             t_date           like SXPGCOLIST-PARAMETERS.
    rep_date = sy-datum - 1.
    t_date = rep_date.
    *p_addparam = '/sap_production/usr/sap/trans/data/zabapftp.sh'.
    refresh t_btcxpm. clear t_btcxpm.
    call function 'SXPG_CALL_SYSTEM'
         EXPORTING
              commandname                = 'ZABAPFTP'
              additional_parameters      = t_date
         TABLES
              exec_protocol              = t_btcxpm
         EXCEPTIONS
              no_permission              = 1
              command_not_found          = 2
              parameters_too_long        = 3
              security_risk              = 4
              wrong_check_call_interface = 5
              program_start_error        = 6
              program_termination_error  = 7
              x_error                    = 8
              parameter_expected         = 9
              too_many_parameters        = 10
              illegal_command            = 11
              others                     = 12.
    if sy-subrc ne 0.
       write:/ 'Error in ZABAPFTP ', sy-subrc.
    endif.
    regards
    vinod

  • 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

  • JavaProcessBuilder freeze to execute external program

    I am trying to run external program using JavaProcessBuilder class. This program doesn't return any status ( it freeze here: int status = mosesPro.waitFor();) when there are more than 20 lines in my test file (command [3, 4]). I would be very thankful for any solution/suggestion. I have attached my sample code below:
    String command [] = new String [5];
    command [0] = "/Users/X/tools/moses/moses-cmd/src/moses";
    command [1] = "-config";
    command [2] = "/Users/X/Documents/thesis/workspace/juneTest/translation/evaluation/filtered.test/moses.ini";
    command [3] = "-input-file";
    command [4] = "/Users/X/Desktop/test2.input";
    try {
    child = new ProcessBuilder(command);
    mosesPro = child.start();
    int status = mosesPro.waitFor();
    if (status == 0) {
    BufferedReader reader = new BufferedReader(new InputStreamReader(mosesPro.getInputStream(), "UTF-8"));
    String line;
    line = reader.readLine();
    while (line != null) {
    System.out.println(line);
    line = reader.readLine();
    reader.close();
    } else {
    BufferedReader errorReader = new BufferedReader(new InputStreamReader(mosesPro.getErrorStream(), "UTF-8"));
    String errLine;
    errLine = errorReader.readLine();
    while (errLine != null) {
    System.out.println(errLine);
    errLine = errorReader.readLine();
    errorReader.close();
    mosesPro.destroy();          
    } catch(Exception ex) {
    ex.printStackTrace();
    }

    You have a deadlock. The stdout buffer is filling so the process is waiting for space to become available. Space can never become available since you don't read the stdout stream until the process has terminated. You should read the 4 sections of http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html and implement the recommendations.
    Note - the 'traps' article is concerned with Runtime.exec() but the traps are just the same with ProcessBuilder.

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

  • 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

  • Execute external program, ErrorStream and InputStream

    I use this command to launch new process:
    Process proc = Runtime.getRuntime().exec(cmd);
    as stated in java doc
    The methods that create processes may not work well for special processes on certain native platforms, such as native windowing processes, daemon processes, Win16/DOS processes on Microsoft Windows, or shell scripts. The created subprocess does not have its own terminal or console. All its standard io (i.e. stdin, stdout, stderr) operations will be redirected to the parent process through three streams (getOutputStream(), getInputStream(), getErrorStream()). The parent process uses these streams to feed input to and get output from the subprocess. Because some native platforms only provide limited buffer size for standard input and output streams, failure to promptly write the input stream or read the output stream of the subprocess may cause the subprocess to block, and even deadlock.
    but I do not need any those streams. what happen if I make proc = null;
    will there be any potential block or deadlock?

    I have read this article before.
    there is usage of waitFor() in example but I do not want to use waitFor().
    I want to launch many processes and monitor them by some other way... for example via sockets...
    right now I launch my process via shell script and redirect STDOUT and STDERR to /dev/null
    is it possible to launch it from java the same way?
    Edited by: NoName on Jan 27, 2009 4:16 AM

  • How can I execute an external program from within a button's event handler?

    I am using Tomcat ApacheTomcat 6.0.16 with Netbeans 6.1 (with the latest JDK/J2EE)
    I need to execute external programs from an event handler for a button on a JSF page (the program is compiled, and extremely fast compared both to plain java and especially stored procedures written in SQL).
    I tried what I'd do in a standalone program (as shown in the appended code), but it didn't work. Instead I received text saying the program couldn't be found. This error message comes even if I try the Windows command "dir". I thought with 'dir' I'd at least get the contents of the current working directory. :-(
    I can probably get by with cgi on Apache's httpd server (or, I understand tomcat supports cgi, but I have yet to get that to work either), but whatever I do I need to be able to do it from within the button's event handler. And if I resort to cgi, I must be able to maintain session jumping from one server to the other and back.
    So, then, how can I do this?
    Thanks
    Ted
    NB: The programs that I need to run do NOT take input from the user. Rather, my code in the web application processes user selections from selection controls, and a couple field controls, sanitizes the inoputs and places clean, safe data in a MySQL database, and then the external program I need to run gets safe data from the database, does some heavy duty number crunching, and puts the output data into the database. They are well insulated from mischeif.
    NB: In the following array_function_test.pl was placed in the same folder as the web application's jsp pages, (and I'd tried WEB-INF - with the same result), and I DID see the file in the application's war file.
            try {
                java.lang.ProcessBuilder pn = new java.lang.ProcessBuilder("array_function_test.pl");
                //pn.directory(new java.io.File("K:\\work"));
                java.lang.Process pr = pn.start();
                java.io.BufferedInputStream bis = (java.io.BufferedInputStream)pr.getInputStream();
                String tmp = new String("");
                byte b[] = new byte[1000];
                int i = 0;
                while (i != -1) {
                    bis.read(b);
                    tmp += new String(b);
                getSelectionsDisplayTextArea().setText(getSelectionsDisplayTextArea().getText() + "\n\n" + tmp);
            } catch (java.io.IOException ex) {
                getSelectionsDisplayTextArea().setText(getSelectionsDisplayTextArea().getText() + "\n\n" + ex.getMessage());
            }

    Hi Fonsi!
    One way to execute an external program is to use the System Exec.vi. You find it in the functions pallet under Communication.
    /Thomas

  • Re: Error while Execute External Operating System Command using T.code SM49

    Dear Experts,
    I Have uploaded one .exe file in the application server (eg: sum.exe) and created the OS command in SM69 transaction .
    And maintained the application server path in the 'operating system command' field in SM69 t.code.
    Our SAP system, oprating system is UNIX.
    After I have executed the external command using transaction SM49 , but I got the below error.
    Can not execute external program (permission denied) , External program terminated with exit code 1
    Immediately I run the SU53 transaction code to check the authorization, but Authorization was successful.
    Could any one please help on this error.
    Thanks in advance.

    >>Can not execute external program (permission denied) , External program terminated with exit code 1
    You need to give the permission as 755 to your file.
    >>I Have uploaded one .exe file in the application server (eg: sum.exe)
    You are on UNIX and do not expect to any result of .exe file as UNIX doesn't know about this.

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

  • LC  2 Error 1003 when executing external command brconnect on (xpgid=0,con

    Dear all,
    I am getting error in sm21.Please suggest .
    Details Page 2 Line 23 System Log: Local Analysis of clusa                    1
    Time     Type Nr  Clt User TCode Grp N Text
    10:00:32 DIA  000 600 DDIC       LC  2 Error 1003 when executing external command brconnect on (xpgid=0,convid=.)
    Error 1003 when executing external command brconnect on (xpgid=0,convid=.)
    Details
    Recording at local and central time........................ 10.05.2010 10:00:32
    Task...... Process                     User...... Terminal Session TCode Program  Cl Problem cl      Package
    06952      Dialog work process No. 000 DDIC                      1       SAPMSSY1 S  Operation Trace SBTC
    No documentation for syslog message LC 2 exists
    Parameter
      1 .... xpgid=0,convid=.
    Technical details
    File Offset RecFm System log Grp N variable message data
      224 260640                  LC  2 brconnect & &Error 1003 & & &
    Regards,
    Kumar

    Dear Juan,
    Please find the logs.Please suggest.
    dev_cp log
    Trace file of control program (trace level 3)
    < Function: BtcTrcInit> Function: main  SAPXPG 720
    2010-05-10--09-33-29 : Before BtcXpgDetach
      > Function: BtcXpgDetach  < Function: BtcXpgDetach  Accept RFC connection from R/3 system
    2010-05-10--09-33-29 : Before RfcAccept
    2010-05-10--09-33-29 : RfcAccept returned OK
    Begin of check_if_security_list
    security check switched OFF
    End of check_if_security_list
    Begin of check_trace_option
    End of check_trace_option
      Install RFC call SAPXPG_START_XPG
      Install RFC call SAPXPG_START_XPG_LONG
      Install RFC call SAPXPG_END_XPG
      Wait for RFC call SAPXPG_START_XPG or SAPXPG_START_XPG_LONG
    2010-05-10--09-33-29 : Before first call of RFCDispatch
    Security: rfcexec_logon_check
      rfcexec_logon_check: logon_user =
      sapxpg_logon_check: rfc_attr.user = BASIS      
      rfcexec_logon_check: client =   
      > Function: BtcXpgStartXpgLong   
    2010-05-10--09-33-29 : Beginning of BtcXpgStartXpgLong
        > Function: BtcXpgStartXpgImportLong      > Function: BtcXpgParam      < Function: BtcXpgParam      > Function: BtcXpgParam      < Function: BtcXpgParam      > Function: BtcXpgParam      < Function: BtcXpgParam      > Function: BtcXpgParam      < Function: BtcXpgParam      > Function: BtcXpgParam      < Function: BtcXpgParam      > Function: BtcXpgParam      < Function: BtcXpgParam      > Function: BtcXpgParam      < Function: BtcXpgParam      > Function: BtcXpgParam      < Function: BtcXpgParam      > Function: BtcXpgTable      < Function: BtcXpgTable    < Function: BtcXpgStartXpgImportLong   
    BtcXpgStartXpgLong: special_trace_flag = <6>
        > Function: BtcXpgStartXpgInt      > Function: BtcXpgItTransfer        Content of source log table:
              Line  Text
              <No StdOut/StdErr output reported>
            Target log table is not identical to source
            ItGetLine terminated with NULL
          < Function: BtcXpgItTransfer      > Function: BtcTrcReset      < Function: BtcTrcReset      Call mode: VIA RFC
          Input arguments of BtcXpgStartXpg:
            External program: brtools
          tracecntl = : 6
          Display of Parameter string switched off !!
            Contents of control flags:
              StdIn control flag: redirect StdIn
              StdOut control flag: store StdOut output in memory
              StdErr control flag: store StdErr output in memory
              Trace control flag: unknown contents
              Termination control flag: control program will wait for termination
          > Function: BtcXpgCheck        > Function: BtcXpgArgv
              parameter number 1:
              parameter number 2:
              parameter number 3:
              parameter number 4:
              parameter number 5:
              parameter number 6:
              parameter number 7:
              Total number of arguments scanned: 7
              Argument argv[0]: brtools
            < Function: BtcXpgArgv      < Function: BtcXpgCheck      > Function: BtcXpgSigInst      < Function: BtcXpgSigInst      > Function: BtcXpgStart        Rearrange stderr to be collected in memory
            Rearrange stdout to be collected in memory
            Redirect stdin, read from NUL:
            > Function: BtcTrcInit< Function: BtcXpgStartStart status of external program: external program successfully started
    Id of external process: 0000005296
    StdOut/StdErr collected in memory
      Line  Text
      <No StdOut/StdErr output reported>
    < Function: BtcXpgStartXpgInt> Function: BtcXpgStartXpgExport  > Function: BtcXpgParam  < Function: BtcXpgParam  > Function: BtcXpgParam  < Function: BtcXpgParam  > Function: BtcXpgParam  < Function: BtcXpgParam< Function: BtcXpgStartXpgExport
    2010-05-10--09-33-29 : End of BtcXpgStartXpgLong
    < Function: BtcXpgStartXpgLong
    2010-05-10--09-33-29 : After first call of RFCDispatch
    Wait for RFC call SAPXPG_END_XPG
    2010-05-10--09-33-29 : Before second call of RFCDispatch
    Security: rfcexec_logon_check
    rfcexec_logon_check: logon_user =
    sapxpg_logon_check: rfc_attr.user = BASIS      
    rfcexec_logon_check: client =
    > Function: BtcXpgEndXpg 
    2010-05-10--09-33-29 : Beginning of BtcXpgEndXpg
      > Function: BtcXpgStartXpgExport    > Function: BtcXpgTable    < Function: BtcXpgTable  < Function: BtcXpgEndXpgImport  > Function: BtcXpgEndXpgInt    > Function: BtcXpgItTransfer      Content of source log table:
            Line  Text
            <No StdOut/StdErr output reported>
          Target log table is not identical to source
          ItGetLine terminated with NULL
        < Function: BtcXpgItTransfer    > Function: BtcXpgReadChild      Output of external command not written to log !!
          Process executing external program has terminated
        < Function: BtcXpgReadChild    > Function: BtcXpgEnd    < Function: BtcXpgEnd    Termination status of external program: no errors reported
        StdOut/StdErr collected in memory
      < Function: BtcXpgEndXpgInt  > Function: BtcXpgEndXpgExport    > Function: BtcXpgParam    < Function: BtcXpgParam    > Function: BtcXpgParam    < Function: BtcXpgParam  < Function: BtcXpgEndXpgExport 
    2010-05-10--09-33-30 : End of BtcXpgEndXpg
    < Function: BtcXpgEndXpg
    2010-05-10--09-33-30 : After second call of RFCDispatch
    2010-05-10--09-33-30 : After call of RfcClose (wait)
    < Function: main
    2010-05-10--09-33-30 : End of SAPXPG: main
    dev_xpg
    Trace file of External Program (trace level 3)
    < Function: BtcTrcInit> Function: BtcXpgStart  External program: brtools -sid prd -F printout alert_log 20100401000000 0128
    Regards,
    Kumar

  • How can an add-on like Firesheep access and execute an external program like Winpcap? Is that a security flaw in Firefox?

    I have been reading about the Firesheep add-on that allows the user to hijack sessions of users on the network by stealing the cookie. I understand that to prevent any application from stealing the cookie, the cookie should not be passed by the site without SSL. However, my understanding of how Firesheep works is that it interfaces with Winpcap (a network sniffer). So my question is "How can an add-on execute an external program or operating system command like Winpcap?" Can any add-on do this and should I be extremely afraid of downloading any add-on because of the potential that it could have complete access to my system?

    Hi Scott-L.
    You asked a very good question and it turns out you're right.
    However, one must be aware that download an Addon on another website that Mozilla may be dangerous. Indeed, the Addons found on the Addon Center are checked (roughly).
    In addition, Firefox includes a blacklist that blocks addons identified as malicious.
    More information here: [http://www.computerworld.com/s/article/9193420/Mozilla_No_kill_switch_for_Firesheep_add_on?taxonomyId=17&pageNumber=1]

  • How Can I execute an external program from my vi?

    Hi guys,
    I want to execute a external program to use it when i called with a bottom. I want push a bottom and execute the program, like acess direct icon or so.
    Any help?.

    Hi Fonsi!
    One way to execute an external program is to use the System Exec.vi. You find it in the functions pallet under Communication.
    /Thomas

Maybe you are looking for

  • Database Performace Report

    Hi We are having many Oracle 10.2.0.3 instances on Unix and Windows . We donot have Enterprise Manager configured and we donot have licence for the diagnostic packs. Requirement : My manager wants a Graphical Report for each database intance showing

  • Creating an Org. Structure in SolMan

    Good Day All; Does anyone know if there is any u201Chow tou201D documentation for creating an u201COrg Structureu201D. Regards Don Newton

  • Check value of Shopping car and PO

    Hi we do have ECS in place with SRM 5.0.- The customer requests a functionality that the SC / PO ist checked upon a limit and in case the value is reached (depending on a customer own defined table) the SC or PO has to be rejected. Do you have any hi

  • Is it possible to add a button with image on the title bar(IDR)?

    I look through all the buttons in the example, All of them does not with an image on them. Is it posslbe to put a image on the title bar? Best regards? Blake Le

  • I have to keep logging in to gmail?

    Several times a day when I check my mail on my iphone 4s It asks me to log in to my gmail again. So I do, but then it has multiple sessions of gmail open. So when I have 6 new messges, it says I have 24. It's also running slowly.