Run like Host command in plsql
Hi,
We are using Host command in sql*plus , but i need to implement like host command in Plsql. I refered previous post and some other links , that most of them are prefered only java stored procedure, And even that restricted previllage.
Can you give some sample example launchiing Win OS command in plsql
venki
To run a batch file, you need to use the Command Shell (and please do not call it a DOS shell like some people tend to do as it is not DOS). E.g.
c:\windows\system32\cmd.exe /c c:\temp\test.bat
We're running cmd.exe with switch /c that tells cmd to execute the command we're passing it, and then to terminate.
Note that we cannot interact with the shell from the PL/SQL side - we cannot answer prompts and so on. The script run, must be a proper batch/non-interactive script.
Also, the Oracle Server process (Win32 thread actually) that is servicing our Oracle client connection, is running the command for us. This thread itself is a background service process. It could run in Windows configured environment (VM/Virtual Machine) that is not allowed to interact with the desktop - or have limited or no access to certain files, folders and programs.
Technically speaking, this is what happens:
1) we pass the command to execute from our client to the Oracle server session servicing us
2) this Oracle thread uses the Java VM to make a Win32 call called CreateProcess()
3) the Win32 kernel executes that process
4) the process starts, runs and terminates
5) the Java VM inside the Oracle Server process regains control and pass the exit code and standard output of that process to PL/SQL
6) PL/SQL in turns, returns that very same data to our client
If you for example run a program that pauses and expects input, or hangs.. it will cause the above series of steps to stop at step 4. With the Java VM waiting on it to complete, and we waiting for the Java VM and PL/SQL call to complete.
Similar Messages
-
Can Reports 3.0 run a host command?
Can Reports 3.0 run a host command like in Forms 5?
nullHi! Bill
ANS: NO
Bill Fox (guest) wrote:
: Can Reports 3.0 run a host command like in Forms 5?
null -
Is there anything like HOST command in Forms in Reports ??
Hello everybody
Is there any command in reports like a HOST command in Forms through which I can call a system command.
My goal is I want to invoke a shell script from my report that will run in the background, do few things and come back to the report once a button is pressed.
Thanks in advance :-)You can4t use the host command, but there is a solution available if you are running 8i with java see http://technet.oracle.com:89/ubb/Forum3/HTML/003262.html
or
http://asktom.oracle.com/pls/ask/f?p=4950:8:102326::NO::F4950_P8_DISPLAYID,F4950_P8_B:150612348067,Y
Hope that will help you -
How to run a HOST command from Report 2.5
Hello everybody,
I want to pass an unix command from a Report. I am running the report (Report 2.5) on an Unix server and I want to pass a unix host command inside the Before Report Trigger of the report. But Report2.5 is not recognising the HOST built-in. Is there is any way around?
Thank in advance.
Samujjwal BasuFirst off is that openssl command correct? Should it be this instead:
openssl pkcs8 -inform der -nocrypt -in test.der -out result.pem
Try out your openssl command within a command prompt so that you know that it works ok. I think the command line you specified waits on stdin (well it does for me).
After that.....
runtime.exec creates a Process object. If you do this:
Process openssl = runtime.exec("....")
then you can examine the return code from openssl to see the exit code - for instance if the input file does not exist then exit = 1. You can test for this with Java
Alternatively you could get the stderr from the process and look inside it - if it is 0 length then all is good, if it has some text in there then it has likely failed. You could then throw an exception and include the stderr output in the exception messgae. You may need to experiment with this, runnig it first when openssl is happy then running it again when openssl is upset.
M -
JDAPI to search for HOST command in PLSQL
Hi All
How do I seach for all host commands in a form. I can convert the form to text or xml but I would like to do that using JDAPI. Has anyone successfully done that.
Any help is appreciated.
Rgds
Arvind BalaramanCan someone help me?
Rgds
Arvind Balaraman -
Using unix host command within plsql on aix
On an aix platform Im trying to host out of a plsql procedure to
use mail. I can only get the host command to work inside a blank
.sql file. ie. first line must have the host command on it. If
you try to imbed the host command within a procedure, the file
will just sit there and nothing happens.
nullJay,
This forum is for Headstart related questions and experiences
only. Please go to metalink.oracle.com to get more information on
your problem.
Regards,
Lauri
Jay Levasseur (guest) wrote:
: On an aix platform Im trying to host out of a plsql procedure
to
: use mail. I can only get the host command to work inside a
blank
: .sql file. ie. first line must have the host command on it. If
: you try to imbed the host command within a procedure, the file
: will just sit there and nothing happens.
null -
Running a Host Command on OEM Grid Control 11g
Hello,
I am trying to execute a host command on a remote windows server but I'm not exactly sure of the syntax of the Command Statement. I am attempting to run the following:
tasklist /FI "IMAGENAME eq myApplication.exe" | grep myApplication.exe
I can run this without issue on the server itself but once I attempt to execute in the host command window I get the following error:
ERROR: Invalid argument option - 'eq'
I am assuming that I need to place an escape character before the quotes but when I place a / before each of the quotes I get the same error. I looked so many place online but have not found anything. Anyone have any ideas? TIA!!!!
-Toddhmm, not so sure this will work, try it on a small directory folder first. If it works great, if not youll have to have some downtime while you move the directory structure to new mount point
stop all GC services.
mv /gc_inst /gc_inst_temp
edit the fstab, create new mount point /gc_inst and mount
mv -R /gc_inst_temp/* /gc_inst
why is gc_inst at 28gb? Seems quite large to me. -
Running a host command from servlet
Hi
I am trying to run some hostcommand/shell scripts from a servlet.Can any one tell me how to go about it.
Rgds,
Satyathis is very useful, I've been looking for a long time but nobody is able to answer me, even my tutor.
andrew -
How to run Unix Host commands from Database Triggers?
Hi
I need to create few directories in the Unix O/s under a specific directory (From a Database Trigger). And the directory names will be determined in the DB Trigger based on the data.
I hope someone would have come across a requirement like this and will be able to help me out.
Thanks.
MohanHi Christopher
How is it possible to use System calls from Triggers. Is it possible to use Runtime Libraries in DB Triggers.
Thanks
Mohan
<BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by Christopher Racicot ([email protected]):
Try using the system calls available in
the C runtime library by calling an external
C procedure from the trigger. We will be
enhancing the support in UTL_FILE to address
issues like this in an upcoming release,
but for now an external procedure should
do the trick.<HR></BLOCKQUOTE>
null -
Hello folks I am trying to create a procedure to run linux host commands. I have found and used code available throughout the internet and it compiles and runs, but no matter what command I send to the host I get a 'Not Found' exception, even if I send as the command the full path to the executable. Here is my code:
*1- Java Procedure*
CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "Host" AS
import java.io.*;
public class Host {
public static void executeCommand(String command) {
try {
String[] finalCommand;
if (System.getProperty("os.name").toLowerCase().indexOf("windows") != -1) {
finalCommand = new String[4];
finalCommand[0] = "C:\\winnt\\system32\\cmd.exe";
finalCommand[1] = "/y";
finalCommand[2] = "/c";
finalCommand[3] = command;
} else { // Linux or Unix System
finalCommand = new String[3];
//finalCommand[0] = "/bin/sh";
//finalCommand[1] = "-c";
//finalCommand[2] = "'" + command + "'";
finalCommand[0] = command;
finalCommand[1] = "";
finalCommand[2] = "";
// Execute the command...
final Process pr = Runtime.getRuntime().exec(finalCommand);
// Capture output from STDOUT...
BufferedReader br_in = null;
try {
br_in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
String buff = null;
while ((buff = br_in.readLine()) != null) {
System.out.println("stdout: " + buff);
try {Thread.sleep(100); } catch(Exception e) {}
br_in.close();
} catch (IOException ioe) {
System.out.println("Error printing process output.");
ioe.printStackTrace();
} finally {
try {
br_in.close();
} catch (Exception ex) {}
// Capture output from STDERR...
BufferedReader br_err = null;
try {
br_err = new BufferedReader(new InputStreamReader(pr.getErrorStream()));
String buff = null;
while ((buff = br_err.readLine()) != null) {
System.out.println("stderr: " + buff);
try {Thread.sleep(100); } catch(Exception e) {}
br_err.close();
} catch (IOException ioe) {
System.out.println("Error printing execution errors.");
ioe.printStackTrace();
} finally {
try {
br_err.close();
} catch (Exception ex) {}
catch (Exception ex) {
System.out.println("Exception: " + ex.getLocalizedMessage());
ex.printStackTrace();
*2- PL/SQL Package*
CREATE OR REPLACE PACKAGE CIF_HOST_PKG IS
PROCEDURE host (p_command IN VARCHAR2);
END CIF_HOST_PKG;
PROCEDURE host (p_command IN VARCHAR2)
AS LANGUAGE JAVA
NAME 'Host.executeCommand (java.lang.String)';
END CIF_HOST_PKG;
*3- Java Permission*
EXEC Dbms_Java.Grant_Permission('CIF', 'SYS:java.lang.RuntimePermission', 'writeFileDescriptor', '');
EXEC Dbms_Java.Grant_Permission('CIF', 'SYS:java.lang.RuntimePermission', 'readFileDescriptor', '');
exec dbms_java.grant_permission( 'CIF', 'SYS:java.io.FilePermission', '/bin/sh', 'execute' );
exec dbms_java.grant_permission( 'CIF', 'SYS:java.io.FilePermission', '/bin/ps', 'read , execute' );
exec dbms_java.grant_permission( 'CIF', 'SYS:java.io.FilePermission', '/bin/ls', 'read , execute' );
*4- Test Code*
set serveroutput on size 1000000
exec dbms_java.set_output(1000000)
exec CIF_HOST_PKG.host('/bin/ls -l');
*5- Test Output*
anonymous block completed
Exception: Exception during creation of the process: java.io.IOException: '/bin/ls -l' not found
java.io.IOException: Exception during creation of the process: java.io.IOException: '/bin/ls -l' not found
at java.lang.OracleProcess.start(OracleProcess.java:259)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:483)
at java.lang.Runtime.exec(Runtime.java:591)
at java.lang.Runtime.exec(Runtime.java:464)
at Host.executeCommand(Host:24)
Any idea on what am I doing wrong?
Thank you in advance,
AndreHas oracle user permissions to /bin/ls ?
try in sqlplus:
host /bin/ls -lIf not try chmod 777 /bin/lsElse you can try my package http://github.com/xtender/xt_svn
select * from table(XT_SVN_TEST.shell_exec('/bin/ls -l /var/tmp'))Best regards,
Malakshinov Sayan -
can i user host command in pl-sql. if so then tell me how i can.
Hi, you can't run a host command
directly from pl/sql.
Look at
http://technet.oracle.com:89/ubb/Forum88/HTML/001295.html
for a short description, how it can be done.
HTH
Detlev -
Hello everyone,
I'm trying to run openVMS host commands via Java using the code listed below, which essentially runs the following host commands, each in turn:
terry :== "hello"
sho sym terry
sho log robin4
I've tried a few other commands as well, but the ones which assign variables (such as the terry example above), never work, either producing no output as in the example above, or if I did
define/group "hello" terry
would produce:
DCL-W-NOCOMD, no command on line - reenter with alphabetic first character
So commands that don't print anything to the screen are the ones that are causing problems (they're just setting variables or what not).
Does anyone have any ideas as to how to get these commands working via java? I really don't know what to think..I've tried checking the format of the commands I'm trying to do, and it's not down to that - the host command I'm running is right and works if done directly.
Please help! Thank you so much in advance.
Robin
import java.io.*;
public class Host {
public static void executeCommand(String command) {
String s = "hello";
String s2 = "sho log robin4";
String s3 = "assign/system "+command+"hello"+command+" robin5";
try {
String[] finalCommand;
System.out.println(System.getProperty("os.name"));
finalCommand = new String[3];
finalCommand[0] = "terry :== \"hello\"";
finalCommand[1] = "sho sym terry";
finalCommand[2] = s2;
for(int i = 0;i< finalCommand.length; i++){
// Execute the command...
final Process pr = Runtime.getRuntime().exec(finalCommand);
// Capture output from STDOUT...
BufferedReader br_in = null;
try {
br_in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
String buff = null;
while ((buff = br_in.readLine()) != null) {
System.out.println("stdout: " + buff);
try {Thread.sleep(100); } catch(Exception e) {}
br_in.close();
} catch (IOException ioe) {
System.out.println("Error printing process output.");
ioe.printStackTrace();
} finally {
try {
br_in.close();
} catch (Exception ex) {}
// Capture output from STDERR...
BufferedReader br_err = null;
try {
br_err = new BufferedReader(new InputStreamReader(pr.getErrorStream()));
String buff = null;
while ((buff = br_err.readLine()) != null) {
System.out.println("stderr: " + buff);
try {Thread.sleep(100); } catch(Exception e) {}
br_err.close();
} catch (IOException ioe) {
System.out.println("Error printing execution errors.");
ioe.printStackTrace();
} finally {
try {
br_err.close();
} catch (Exception ex) {}
catch (Exception ex) {
System.out.println(ex.getLocalizedMessage());User_resU wrote:
Hello everyone,
I'm trying to run openVMS host commands via Java using the code listed below, which essentially runs the following host commands, each in turn:
terry :== "hello"
sho sym terry
sho log robin4
1. Presumably this represents some sort of character user interface (CUI) which is console based.
finalCommand = new String[3];
finalCommand[0] = "terry :== \"hello\"";
finalCommand[1] = "sho sym terry";
finalCommand[2] = s2;
final Process pr = Runtime.getRuntime().exec(finalCommand);
2. This represents an executable to which you are passing command line arguments.
This isn't a java problem because 1 and 2 are not even close to being the same.
Java won't do anything that you cannot get the application to do itself.
Your choices:
1. Find a way to run the app such that it takes commands from a file. You put the commands in a file and pass that to exec()
2. Find a way that use stdio (the CUI might represent that but there is no guarantee.) You then use exec() to start the app then use the IO streams to pass the commands to it.
Notice that my choices do not include an option for passing as command line parameters because I am almost certain that it does not exist. -
Calling java host command in trigger/PLSQL
I created a java call to execute a linux host command that calls a shell script that will echo out a result. It is owned by SYS and has granted execute to SYSTEM. SYSTEM has a table that monitors accesses to the RDBMS. When a user logs on from a remote server vis sqlplus, this LOGON trigger write to the SYSTEM table (successfully). SYSTEM has a trigger that runs a linux command to execute a shell script that pulls the actual IP address from the remote system. I can run this call from a PLSQL block (outside the trigger) and get a response back like "user:101.101.101.111" but when I have the same user log on, the trigger fires - no errors or exceptions yet no rows are returned. Is there some restriction in a trigger versus just a plsql block call? The java code used is what I found on (http://www.oracle-base.com/articles/8i/ ... mPLSQL.php) and it works perfectly OUTSIDE the trigger but nothing is returned in the trigger firing steps. Any idea?
rdbms: 11.1.0.7, Redhat 4
I know the code works because I can write the host command output to a file. Later in the trigger I can open the file and can read the data that should have been returned in the java host call.FYI - here is the code from your site that I used:
DROP JAVA SOURCE SYS."Host";
CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED SYS."Host" as import java.io.*;
public class Host {
public static void executeCommand(String command) {
try {
String[] finalCommand;
if (isWindows()) {
finalCommand = new String[4];
// Use the appropriate path for your windows version.
finalCommand[0] = "C:\\windows\\system32\\cmd.exe"; // Windows XP/2003
//finalCommand[0] = "C:\\winnt\\system32\\cmd.exe"; // Windows NT/2000
finalCommand[1] = "/y";
finalCommand[2] = "/c";
finalCommand[3] = command;
else {
finalCommand = new String[3];
finalCommand[0] = "/bin/sh";
finalCommand[1] = "-c";
finalCommand[2] = command;
final Process pr = Runtime.getRuntime().exec(finalCommand);
pr.waitFor();
new Thread(new Runnable(){
public void run() {
BufferedReader br_in = null;
try {
br_in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
String buff = null;
while ((buff = br_in.readLine()) != null) {
System.out.println("Cmd results: " + buff);
try {Thread.sleep(100); } catch(Exception e) {}
br_in.close();
catch (IOException ioe) {
System.out.println("Exception caught printing process output.");
ioe.printStackTrace();
finally {
try {
br_in.close();
} catch (Exception ex) {}
}).start();
new Thread(new Runnable(){
public void run() {
BufferedReader br_err = null;
try {
br_err = new BufferedReader(new InputStreamReader(pr.getErrorStream()));
String buff = null;
while ((buff = br_err.readLine()) != null) {
System.out.println("Cmd Error: " + buff);
try {Thread.sleep(100); } catch(Exception e) {}
br_err.close();
catch (IOException ioe) {
System.out.println("Exception caught printing process error.");
ioe.printStackTrace();
finally {
try {
br_err.close();
} catch (Exception ex) {}
}).start();
catch (Exception ex) {
System.out.println(ex.getLocalizedMessage());
public static boolean isWindows() {
if (System.getProperty("os.name").toLowerCase().indexOf("windows") != -1)
return true;
else
return false;
/ -
How to run a script from Oracle Form (Beside using HOST command)
I would like to run a script from Forms 6.0. I know that we can actually issue this command :
host('plus80.exe' username/password@connect_string @c:\scriptname);
BUT, is there any other alternative ?Sqlplus is a different program, so one way or the other you have to leave Forms to run sqlplus. What is you objection against HOST?
You can also run sqlplus from the database, but again you need a stored java procedure to call sqlplus (sort of HOST command that runs in the database).
Francois' solution works if your script just has a query to run, but if you have specific sqlplus commands (spool etc.) forms_ddl is probably not a solution. -
Not able to create Oracle External Procedure to Run Host Commands
Trying to follow this article
http://timarcher.com/node/9
Its related to
Oracle External Procedure to Run Host Commands
steps
1)mkdir –p /u01/app/usfapp/oracle_external_procs/oracle_host
2)
Author is suggesting to create a file
but header file is missing in very first line... may be not sure..say it is <stdio.h>Create a file named oracle_host.c. The contents of this file will be:
#include
int RunCmd(char *cmd)
return(system(cmd));
4) Create the file named makefile. The contents of this file will be:
oracle_host: oracle_host.o
gcc -shared -o oracle_host.so oracle_host.o
$ cat makefile
oracle_host: oracle_host.o
gcc -shared -o oracle_host.so oracle_host.o
5)
Now run the command make
The output on my server looks like:
[u01/app/usfapp/oracle_external_procs/oracle_host]
banner@usfbannerte [TRNG] > make
gcc -shared -o oracle_host.so oracle_host.o
here I stuck .. Not able to run this step ]$ make
gcc -shared -o oracle_host.so oracle_host.o
/usr/bin/ld: oracle_host.o: relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC
oracle_host.o: could not read symbols: Bad value
collect2: ld returned 1 exit status
make: *** [oracle_host] Error 1
Any one has any idea what went wrong
Any other link related to this is most welcomed.
Please suggest ...hi
please update
or
provide any other link / document for
Oracle External Procedure to Run Host Commands
--using c
Thanks in advance.
Maybe you are looking for
-
Hi all, Does anyone know, in which database table we can find the list of logical systems, which are RFC targets of a system. In table TBDLS, I found the logical systems for the clients of a system, but I want to know if a logical system given as a
-
Excel 2013 RTD links / macro stopped working
I have a new laptop with Windows 8.1 and Office 2013 that was pulling in data via an RTD link into excel without problems until a couple of days ago. The same system works perfectly with XP and Excel 2010. I reinstalled the application (Prophet X)
-
I can not restore my ipad, its giving the message
I can not restore my ipad its giving the message : The Ipad could not be restored, an unknown error has occured (1)
-
My phone will not connect with my itunes so that I can sync them.
My phone will not connect with my itunes so that I can sync them and update my music on my phone. How can I fix this? I have tried everything I know and could find to do.
-
Chase told me that there was a browser problem like some piece of malware. I used Mac's Disk Utility and verified and repaired things. I deleted all Firefox files, and downloaded the entire program again, reinstalled it, and the same situation happen