Oracle Java Stored Procedure calls Unix shell

Source: Internet
Author: User

Reference: Doc ID 109095.1

First, create a Java class that calls Unix shellon the database, and use runtime.getruntime(cmd.exe c () to implement

1.

Create or replace java source named "CaptureStream"
Import java. util .*;
Import java. io .*;

Class CaptureStream implements Runnable {
Private final InputStream is;
Private final String type;
Private final OutputStream redirect;
Private boolean redirected = false;


CaptureStream (InputStream is, String type, OutputStream redirect)
{
This. is = is;
This. type = type + "> ";
This. redirect = redirect;
}

CaptureStream (InputStream is, String type)
{
This (is, type, null );
}


CaptureStream (InputStream is)
{
This (is, "", null );
}

Public void run ()
{

Try {
PrintWriter pw = null;
If (redirect! = Null ){
Pw = new PrintWriter (redirect );
Redirected = true;
}


InputStreamReader isr = new InputStreamReader (is );
BufferedReader br = new BufferedReader (isr );
String line = null;
While (line = br. readLine ())! = Null ){
System. out. println (type + line );
If (redirected ){
Pw. println (line );
}
}
If (redirected ){
Pw. flush ();
Pw. close ();
}
Br. close ();
Isr. close ();
} Catch (IOException ioe ){
Ioe. printStackTrace ();
}
}
};
/

  • 1
  • 2
  • 3
  • Next Page

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.