Home » Infrastructure » Linux » shell command 'cd / ' in PL/SQL
shell command 'cd / ' in PL/SQL [message #99261] Sun, 02 January 2005 21:06 Go to next message
Samyak
Messages: 10
Registered: August 2004
Junior Member
hi,
i made a java stored procedure that can run from PL/SQL procedure to invoke shell commands .
now as a normal user i am not able to execute the following command 'cd /' from it....
can we issue 'cd /' from PL/SQL ...
awaiting response,
thanks
Re: shell command 'cd / ' in PL/SQL [message #99262 is a reply to message #99261] Mon, 03 January 2005 04:06 Go to previous messageGo to next message
Frank Naude
Messages: 4571
Registered: April 1998
Senior Member
Hi,

Unfortunately not. Your program will start a shell, execute the "cd /" command successfully, and then exit. The net result is you are still be in the parent shell's current working directory.

Best regards.

Frank
Re: shell command 'cd / ' in PL/SQL [message #99264 is a reply to message #99262] Mon, 03 January 2005 18:12 Go to previous messageGo to next message
Samyak
Messages: 10
Registered: August 2004
Junior Member
thanks for replying frank....
so is there no other way i can do this....
because i wanted to get out from my current working directory and go to folder (say) /mnt/A ....here folder A is the mount at which my windows machine is shared with linux....the complete command i want to execute via stored procedure is .....
cd /mnt/A | ls -1tr > bb.txt ..........
but it is not allowing me to do so.....
i cannot figure out what to do....
any turnaround......
Re: shell command 'cd / ' in PL/SQL [message #99267 is a reply to message #99264] Tue, 04 January 2005 22:56 Go to previous messageGo to next message
Frank Naude
Messages: 4571
Registered: April 1998
Senior Member
Can you please prepare a small test case and post the source so I can test it?

Best regards.

Frank
Re: shell command 'cd / ' in PL/SQL [message #99268 is a reply to message #99267] Wed, 05 January 2005 00:08 Go to previous message
Samyak
Messages: 10
Registered: August 2004
Junior Member
here is the Java source created........
CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED "Host" AS
import JAVA.io.*;
PUBLIC CLASS Host {
PUBLIC static void executeCommand(String command) {
try {
String[[]] finalCommand;
IF (isWindows()) {
finalCommand = NEW String[[4]];
finalCommand[[0]] = "C:\windows\system32\cmd.exe";
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);
NEW THREAD(NEW Runnable() {
PUBLIC void RUN() {
try {
BufferedReader br_in = NEW BufferedReader(NEW InputStreamReader(pr.getInputStream()));
String buff = NULL;
WHILE ((buff = br_in.readLine()) != NULL) {
SYSTEM.OUT.println("Process out :" + buff);
try {THREAD.sleep(100); } catch(EXCEPTION e) {}
}
br_in.CLOSE();
}
catch (IOException ioe) {
SYSTEM.OUT.println("Exception caught printing process output.");
ioe.printStackTrace();
}
}
}).START();

NEW THREAD(NEW Runnable() {
PUBLIC void RUN() {
try {
BufferedReader br_err = NEW BufferedReader(NEW InputStreamReader(pr.getErrorStream()));
String buff = NULL;
WHILE ((buff = br_err.readLine()) != NULL) {
SYSTEM.OUT.println("Process err :" + buff);
try {THREAD.sleep(100); } catch(EXCEPTION e) {}
}
br_err.CLOSE();
}
catch (IOException ioe) {
SYSTEM.OUT.println("Exception caught printing process error.");
ioe.printStackTrace();
}
}
}).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;
}

};
/
then here is the 1st oracle standard procedure that calls the above java class.....

CREATE OR REPLACE PROCEDURE Host_Command (p_command IN VARCHAR2)
AS LANGUAGE JAVA
NAME 'Host.executeCommand (java.lang.String)';
/

After this i created my oracle PL/SQL procedure which will use the host_command to execute shell commands from oracle.......

CREATE OR REPLACE PROCEDURE Call_Host(p_file_name VARCHAR2)
AS

BEGIN
--this is for test only-------------------

Host_Command (p_command => 'cd /');
Host_Command (p_command => 'ls -1tr > /home/aa.txt');


END;
/

but instead of this it shows me list of files in /home/oracle/OraHome1/dbs when i execute the pl/sql procedure from my windows machine.i tried after giving all permissions but to no avail.....
Previous Topic: root passwd
Next Topic: Mandrake 10.0 and Oracle 9.2.0.4 OUI Freeze
Goto Forum:
  


Current Time: Sun Nov 27 03:07:00 CST 2022