Home » Infrastructure » Unix » Write to Unix/Linux FIFO
Write to Unix/Linux FIFO [message #49003] Thu, 06 January 2005 22:49 Go to next message
Fahami
Messages: 22
Registered: December 2004
Junior Member
Hi there,

Is there any way/syntax in Oracle Store Procedure where I can write into Linux/Unix FIFO? I tried to use UTL_FILE utility but cannot. I always get ORA-29283, invalid file operation error.

CREATE OR REPLACE PROCEDURE sp_write_fifo
( iv_path VARCHAR2, iv_file VARCHAR2 )
IS
outf UTL_FILE.FILE_TYPE;
BEGIN
outf := UTL_FILE.FOPEN(UPPER(iv_path), iv_file, 'A');

UTL_FILE.PUT_LINE(outf,'Store Procedure');
UTL_FILE.PUT_LINE(outf,'by Fahami');

UTL_FILE.FCLOSE(outf);
END sp_write_fifo;

I created the path using CREATE DIRECTORY command.

Thanks & Regards
Re: Write to Unix/Linux FIFO [message #49004 is a reply to message #49003] Thu, 06 January 2005 23:54 Go to previous messageGo to next message
Sam
Messages: 255
Registered: April 2000
Senior Member
hi fahami...
first of all where are you executing your procedure from ..... and do you have permissions to the linux machine.... if everything is in place then what type of file operation do you want to execute...

regards ,
sam
Re: Write to Unix/Linux FIFO [message #49005 is a reply to message #49003] Fri, 07 January 2005 01:46 Go to previous messageGo to next message
Frank Naude
Messages: 4581
Registered: April 1998
Senior Member
Hi,

You can write to a pipe as you would normally write to a plain text file. Here is an example:

Session 1: setup the pipe
$ mknod pipe.txt p
$ cat pipe


Session 2: Write to the pipe
SQL> CREATE OR REPLACE DIRECTORY dir1 AS '/app/oracle';

Directory created.

SQL>
SQL> DECLARE
  2    fileHandler UTL_FILE.FILE_TYPE;
  3  BEGIN
  4    fileHandler := UTL_FILE.FOPEN('DIR1', 'pipe.txt', 'W');
  5    UTL_FILE.PUTF(fileHandler, 'Look ma, I''m writing to a pipe!!!n');
  6    UTL_FILE.FCLOSE(fileHandler);
  7  EXCEPTION
  8    WHEN utl_file.invalid_path THEN
  9       raise_application_error(-20000, 'ERROR: Invalid path for file.');
 10  END;
 11  /

PL/SQL procedure successfully completed.


Best regards.

Frank
Re: Write to Unix/Linux FIFO [message #49013 is a reply to message #49005] Fri, 07 January 2005 05:38 Go to previous messageGo to next message
Thomas G
Messages: 58
Registered: April 2003
Member
Could it propably be that it only works if the other side of the pipe (e.g. the cat) ist already running when you run the procedure ?
Re: Write to Unix/Linux FIFO [message #49015 is a reply to message #49013] Fri, 07 January 2005 05:47 Go to previous messageGo to next message
William Robertson
Messages: 1643
Registered: August 2003
Location: London, UK
Senior Member
It will work but the procedure will hang until something reads off the pipe.
Re: Write to Unix/Linux FIFO [message #49035 is a reply to message #49005] Sun, 09 January 2005 18:08 Go to previous messageGo to next message
Fahami
Messages: 22
Registered: December 2004
Junior Member
Hi,

It can not work! I already did all before. I always got these error when executing the procedure:
BEGIN sp_write_fifo; END;

*
ERROR at line 1:
ORA-29283: invalid file operation
ORA-06512: at "SYS.UTL_FILE", line 449
ORA-29283: invalid file operation
ORA-06512: at "EMS.SP_WRITE_FIFO", line 5
ORA-06512: at line 1

FYI, the Oracle 9i server is located on the Win 2000 Server. I also have setup a map directory on the Win server to the Linux dir where the FIFO should be write to. The procedure is to be run at the client (the Linux machine).

Thanks & Regards.
Re: Write to Unix/Linux FIFO [message #49036 is a reply to message #49004] Sun, 09 January 2005 18:10 Go to previous messageGo to next message
Fahami
Messages: 22
Registered: December 2004
Junior Member
Hi Sam,

It can not work! I already did all before. I always got these error when executing the procedure:
BEGIN sp_write_fifo; END;

*
ERROR at line 1:
ORA-29283: invalid file operation
ORA-06512: at "SYS.UTL_FILE", line 449
ORA-29283: invalid file operation
ORA-06512: at "EMS.SP_WRITE_FIFO", line 5
ORA-06512: at line 1

FYI, the Oracle 9i server is located on the Win 2000 Server. I also have setup a map directory on the Win server to the Linux dir where the FIFO should be write to. The procedure is to be run at the client (the Linux machine).

Thanks & Regards.
Re: Write to Unix/Linux FIFO [message #49045 is a reply to message #49036] Mon, 10 January 2005 14:41 Go to previous messageGo to next message
Sunita
Messages: 6
Registered: November 2002
Junior Member
Hi,

Can you change the FOPEN function to the following and give it a try.
outf := UTL_FILE.FOPEN(UPPER(iv_path), iv_file, 'W');

I think that with a 'A' - (stands for append) value for the third parameter, the procedure tries to check for the existence of the file, before appending into the file. If the file does not exist, you can get an error.

Also, when you try to execute the package, you would have to pass parameter values for iv_path and iv_file.
eg.
BEGIN sp_write_fifo('directory_name','file_name') END;

good luck.

Sunita
Re: Write to Unix/Linux FIFO [message #49047 is a reply to message #49003] Mon, 10 January 2005 18:52 Go to previous message
Sam
Messages: 255
Registered: April 2000
Senior Member
alright fahami,
first see whether the linux machine is visible from your windows machine...if yes, then it is shared with windows....then instead of specifying through directory path... first try to read the file by directly assigning the pathname .... if it is working , then your file is not opening under valid permissions.....
Previous Topic: SQL*Loader errors in the log
Next Topic: Urgent solution required
Goto Forum:
  


Current Time: Tue Nov 26 03:12:02 CST 2024