Quantcast
Channel: Process Integration (PI) & SOA Middleware
Viewing all articles
Browse latest Browse all 741

Trick to execute OS command on SAP PI

$
0
0

Dear Friends,

 

Usually a PI developer will not get an OS level access to the system and he has to be heavily reliant on a SAP technical consultant (My basis friend hates me when I call him a basis guy ) to get any OS level job done. In dual stack systems, one could execute external OS commands on SM49 t-code.


So, a simple alternative is to use the below code snippet on either a UDF or java-mapping.


try

{

   java.lang.Runtime rt = java.lang.Runtime.getRuntime();

        // Start a new process: UNIX command ls

        java.lang.Process p = rt.exec("ls");

        // You can or maybe should wait for the process to complete

        p.waitFor();

     

container.getTrace().addWarning("Process exited with code = " + p.exitValue());

// System.out.println("Process exited with code = " + rt.exitValue());

        // Get process' output: its InputStream

        java.io.InputStream is = p.getInputStream();

        java.io.BufferedReader reader = new java.io.BufferedReader(new InputStreamReader(is));

        // And print each line

        String s = null;

        while ((s = reader.readLine()) != null) {

container.getTrace().addWarning("Process exited with code = " + s);

            //System.out.println(s);

        }

        is.close();

}catch(Exception e)   

{

e.printStackTrace();

}

 

 

 

 

return input;

Hope this is useful!!


Viewing all articles
Browse latest Browse all 741

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>