Using utl_file and unix pipes

Hi,
I'm trying to use utl_file and unix pipes to communicate with a unix process.
Basically I want the unix process to read off one pipe and give me back the result on a different pipe.
In the example below the unix process is a dummy one just copying the input to the output.
I cant get this to work for a single plsql block writing and reading to/from the pipes - it hangs on the first read of the return pipe.
Any ideas?
======== TEST CASE 1 ===============
create directory tmp as '/tmp';
on unix:
cd /tmp
mknod outpip p
mknod inpip p
cat < inpip > outpip
drop table res;
create table res (m varchar2(200));
declare
l_filehandle_rec UTL_FILE.file_type;
l_filehandle_send UTL_FILE.file_type;
l_char VARCHAR2(200);
begin
insert into res values ('starting');commit;
l_filehandle_send := UTL_FILE.fopen ('TMP', 'inpip', 'A', 32000);
insert into res values ('opened inpip ');commit;
l_filehandle_rec := UTL_FILE.fopen ('TMP', 'outpip', 'R', 32000);
insert into res values ('opened outpip ');commit;
FOR i in 1..10 LOOP
utl_file.put_line(l_filehandle_send,'line '||i);
insert into res values ('written line '||i); commit;
utl_file.get_line(l_filehandle_rec,l_char);
insert into res values ('Read '||l_char);commit;
END LOOP;
utl_file.fclose(l_filehandle_send);
utl_file.fclose(l_filehandle_rec);
END;
in a different sql session:
select * from res:
starting
opened inpip
opened outpip
written line 1
============ TEST CASE 2 =================
However If I use 2 different sql session (not what I want to do...), it works fine:
1. unix start cat < inpip > outpip
2. SQL session 1:
set serveroutput on size 100000
declare
l_filehandle UTL_FILE.file_type;
l_char VARCHAR2(200);
begin
l_filehandle := UTL_FILE.fopen ('TMP', 'outpip', 'R', 32000);
FOR i in 1..10 LOOP
utl_file.get_line(l_filehandle,l_char);
dbms_output.put_line('Read '||l_char);
END LOOP;
utl_file.fclose(l_filehandle);
END;
3. SQL session 2:
set serveroutput on size 100000
declare
l_filehandle UTL_FILE.file_type;
begin
l_filehandle := UTL_FILE.fopen ('TMP', 'inpip', 'A', 32000);
FOR i in 1..10 LOOP
utl_file.put_line(l_filehandle,'line '||i);
--utl_lock.sleep(1);
dbms_output.put_line('written line '||i);
END LOOP;
utl_file.fclose(l_filehandle);
END;
/

> it hangs on the first read of the return pipe.
Correct.
A pipe is serialised I/O device. One process writes to the pipe. The write is blocked until a read (from another process or thread) is made on that pipe. Only when there is a reader for that data, the writer is unblocked and the actual write I/O occurs.
The reverse is also true. A read on the pipe is blocked until another process/thread writes data into the pipe.
Why? A pipe is a memory structure - not a file system file. If the write was not blocked the writer process can writes GBs of data into the pipe before a reader process starts to read that data. This will drastically knock memory consumption and performance.
Thus the purpose of a pipe is to serve as a serialised blocking mechanism between a reader and a writer - allowing one to write data that is read by the other. With minimal memory overheads as the read must be serviced by a write and a write serviced by a read.
If you're looking for something different, then you can open a standard file in share mode and write and read from it using two different file handles within the same process. However, the file will obviously have a file system footprint ito space (growing until the writer stops and the reader terminates and trashes the file) .
OTOH a pipe's footprint is minimal.

Similar Messages

  • How to generate a empty file in AL11 using ABAP and unix command

    Hi Experts,
    when load infopackage triggers it will search file from AL11 if file is available it will get loaded successfully.  When there is no file in AL11 error while opening file (orgin A) and the load will fail.  At this level i have to write a abap code using unix command to generate a empty file.
    Is there any way to achieve the above requirement.
    Thanks
    Vara

    Hi,
    If i get your requirement properly then you want to create a blank file if there is no file on the application server so that your infopackage does not fail, am i correct.
    If this is your requirement then this can be easily done if you use process chain to load the file via infopackage. Follow the following steps:
    1. Add a ABAP program before the infopackage and check if the file is present on the server or not. Use a simple ABAP statement OPEN DATASET <FNAME>. Check the SY-SUBRC after this statement if it is not 0 then it means that the file does not exist on the application server.
    2. Once you have established that the file is not present create a flat file using a code similar to the below one
    OPEN DATASET FILENAME FOR OUTPUT IN TEXT MODE
                          MESSAGE D_MSG_TEXT.
    IF SY-SUBRC NE 0.
      WRITE: 'File cannot be opened. Reason:', D_MSG_TEXT.
      EXIT.
    ENDIF.
    * Transferring Data
    LOOP AT INT_table.
      TRANSFER INT_table-field1 TO FILENAME.
    ENDLOOP.
    * Closing the File
    CLOSE DATASET FILENAME.
    3. Add your infopackage step after this ABAP program in your process chain.
    I hope this helps.
    Best Regards,
    Kush Kashyap

  • How to store php sessions using memcached and unix socket

    I am running Arch linux with systemd, nginx, and php with php-fpm. I am trying (and failing) to configure memcached to store sessions using a unix socket. I have memcached installed and active, however, I am unable to disable networking. I added the following line to /etc/conf.d/memcached
    MEMCACHED_ARGS="-s unix:///tmp/memcached.sock -a 666"
    I also tried:
    MEMCACHED_ARGS="-s /tmp/memcached.sock -a 666"
    MEMCACHED_ARGS="-s unix:/tmp/memcached.sock -a 666"
    when I restart memcached I always get:
    memcached.service - Memcached Daemon
              Loaded: loaded (/usr/lib/systemd/system/memcached.service; enabled)
              Active: active (running) since Sat 2013-01-19 17:41:15 PST; 5min ago
            Main PID: 773 (memcached)
              CGroup: name=systemd:/system/memcached.service
                      └─773 /usr/bin/memcached -l 127.0.0.1
    when I run php script with sessions php error log shows (not surprisingly):
    [19-Jan-2013 16:46:45 America/Los_Angeles] PHP Warning:  Unknown: Failed to write session data (memcached). Please verify that the current setting of session.save_path is correct (unix:/tmp/memcached.sock) in Unknown on line 0
    I also installed the php-memcached package but I don't what it does or how to get it going. I uncommented the following line in /etc/php/conf.d/memcached.ini:
    extension=memcached.so
    but that didn't change anything.
    Any insights or suggestions would be greatly appreciated.

    Look at this link -http://odiexperts.com/getting-one-or-several-unknown-files-from-a-directory
    change the command to fetch the ls command and write into File and then using either java or jython break the data and fetch the file name and date and insert into log table.
    (or)
    you can use the os.system command and get the complete ls command into string and then process and insert it.
    Let us know if you need any other help.

  • Error while using UTL_FILE package

    I am getting error while using UTL_FILE package in apex 3.0 version
    Pls help me out.

    ok, how are you using UTL_FILE and what is the error?

  • How to skip the header rows of the file using UTL_FILE?

    Hi,
    I created a procedure to read the file from shared location using UTl_FILE package. But, I stucked why because I don't know how to skip the header rows as those rows are headings for one of the report.Since, please help me.
    Regards,
    Vissu.....

    vissu wrote:
    Hi,
    I created a procedure to read the file from shared location using UTl_FILE package. But, I stucked why because I don't know how to skip the header rows as those rows are headings for one of the report.Since, please help me.
    Regards,
    Vissu.....UTL_FILE just reads data from the file. It has no concept of what could be a "header" or "body" or "records" or "footer" or any other data based concept. If you want to skip lines of a file, you will just need to read them using UTL_FILE and ignore them.

  • VIs for using UNIX pipes?

    We're going to start working on an application that will eventually run on
    a UNIX machine, but in the meantime we'll develop on NT, which is what we're
    familiar with. One requirement is to communicate with another process through
    a UNIX pipe. Are there VIs built into the UNIX versions of LabVIEW for this?
    Or do we just use file I/O VIs? Or is there some other way to accomplish
    this?
    If there are VIs built in, where is the documentation? I checked the LabVIEW
    manuals, but I didn't find anything.
    Russell Davoli

    Russell Davoli wrote:
    > We're going to start working on an application that will eventually run on
    > a UNIX machine, but in the meantime we'll develop on NT, which is what we're
    > familiar with. One requirement is to communicate with another process through
    > a UNIX pipe. Are there VIs built into the UNIX versions of LabVIEW for this?
    > Or do we just use file I/O VIs? Or is there some other way to accomplish
    > this?
    >
    > If there are VIs built in, where is the documentation? I checked the LabVIEW
    > manuals, but I didn't find anything.
    >
    > Russell Davoli
    Yes there are VIs for named pipes in UNIX, Open, Close, Read, and Write
    They are under the communication palette. Check the online manual in the comm
    section.
    Kevin (my email is down)

  • Expdb using Unix pipe command for max compression

    I think the answer to this is NO, but I thought I'd ask the questions anyway, in case some of the Oracle geniuses on this site have figured out a way around this.
    We have been using the existing exp/imp commands for years, due to the fact that we can pipe the output through a pre-setup file that will compress the data as it is written. Since we have moved onto the 10g and now the v11 software, we are starting to what to utilize the parallelism that is afforded in expdp, but don't want to deal with the space required for non-fully compressed exports that occurs with expdp.
    So the question is, has anyone figured out a way to use expdp and using 'on the fly' compression like you could do with the old exp utility on Unix boxes??
    Any help would be appreciated....

    Unfortunately, no--it has to do with the parallel nature of the file ops that prevents compression through a pipe. However, if you buy the Compression option in 11--you can compress on the fly.
    See this white paper.
    http://www.oracle.com/technology/products/database/utilities/pdf/datapump11g2007_quickstart.pdf
    Edited by: jdanton on Sep 2, 2008 3:12 PM

  • Error Using Directories and UTL_FILE package

    Dear All, I have a problem using UTL_FILE package...
    When I'm trying to write into a directory I get the following error message:
    ORA-29283: invalid file open
    I have a Directory named "TMPDIRPD". I checked the permissions over this directory and found that
    'OPS$PDRVBPP' user has OS permissions over it. I supposed that it was the user used to validate permissions.
    Plus, I verified that user "OPS$PDRDVBPP" has read/write permission into directory with this query:
    SELECT TP.grantee,
    TP.privilege
    FROM dba_tab_privs TP,
    dba_role_privs RP
    WHERE TP.table_name = 'TMPDIRPD'
    AND TP.grantee = RP.granted_role
    AND rp.grantee = 'OPS$PDRDVBPP';
    But I'm getting the same error message.
    Then I saw that 'OPS$PDRDVBPP' user calls UTL_FILE package through another package, and isn't the owner of it...
    This package - who belongs to another database user - is using the OS user who owns the Oracle Installation instead 'OPS$PDRVBPP'. Isn't it?
    I also checked that operative system user has read-write permissions, and asked it to the OS Administrator. He told me that oracle user has read-write permissions over this directory too... I don't know what more else can be wrong.
    Have anyone some idea to fix this?

    Roman, I sorry about missed info.
    This is the version:
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Prod
    PL/SQL Release 10.2.0.4.0 - Production
    "CORE     10.2.0.4.0     Production"
    TNS for Linux: Version 10.2.0.4.0 - Production
    NLSRTL Version 10.2.0.4.0 - Production
    It's running over a Unix server (I really don´t know the exact version but it's a suse Linux).
    I though in ORACLE Directory object named TMPDIRPD, and its directory_path defined like /companyFiles/thishost/proj/pdrdvbpp/appfiles/tmp (OS Directory).
    I wrote into a OS directory using one of the procedures or functions inside the UTL_FILE package (SYS.UTL_FILE.FOPEN(parameter_path,parameter_file,parameter_io)).
    Here it goes an example of code.
    DECLARE
    v_AbroLog UTL_FILE.FILE_TYPE;
    BEGIN
    v_AbroLog := UTL_FILE.FOPEN('TMPDIRPD','log_prueba_utl.'||to_char(sysdate,'mmddy
    yyy'), 'a');
    UTL_FILE.PUT_LINE(v_AbroLog,'PRUEBA OK');
    UTL_FILE.FCLOSE(v_AbroLog);
    END;
    quit
    SQL> @test_utl.sql;
    DECLARE
    ERROR at line 1:
    ORA-29283: invalid file open
    some other generic error messages
    This error happens when the file doesn't exists.

  • HOW TO READ DATA FROM A FILE AND INSERT INTO A TABLE USING UTL_FILE

    Hi..
    I have a file.I want to read the data from file and load it into a table using utl_file.
    how can I do it?
    Any reply apreciated...

    Hi,
    This is not your requirment but u can try this :
    CREATE OR REPLACE DIRECTORY text_file AS 'D:\TEXT_FILE\';
    GRANT READ ON DIRECTORY text_file TO fah;
    GRANT WRITE ON DIRECTORY text_file TO fah;
    DROP TABLE load_a;
    CREATE TABLE load_a
    (a1 varchar2(20),
    a2 varchar2(200))
    ORGANIZATION EXTERNAL
    (TYPE ORACLE_LOADER
    DEFAULT DIRECTORY text_file
    ACCESS PARAMETERS
    (FIELDS TERMINATED BY ','
    LOCATION ('data.txt')
    select * from load_a;
    CREATE TABLE A AS select * from load_a;
    SELECT * FROM A
    Regards
    Faheem Latif

  • How to get UTF-8 encoding when create XML using DBMS_XMLGEN and UTL_FILE ?

    How to get UTF-8 encoding when create XML using DBMS_XMLGEN and UTL_FILE ?
    Hi,
    I do generate XML-Files by using DBMS_XMLGEN with output by UTL_FILE
    but it seems, the xml-Datafile I get on end is not really UTF-8 encoding
    ( f.ex. cannot verifying it correct in xmlspy )
    my dbms is
    NLS_CHARACTERSET          = WE8MSWIN1252
    NLS_NCHAR_CHARACTERSET     = AL16UTF16
    NLS_RDBMS_VERSION     = 10.2.0.1.0
    I do generate it in this matter :
    declare
    xmldoc CLOB;
    ctx number ;
    utl_file.file_type;
    begin
    -- generate fom xml-view :
    ctx := DBMS_XMLGEN.newContext('select xml from xml_View');
    DBMS_XMLGEN.setRowSetTag(ctx, null);
    DBMS_XMLGEN.setRowTag(ctx, null );
    DBMS_XMLGEN.SETCONVERTSPECIALCHARS(ctx,TRUE);
    -- create xml-file:
    xmldoc := DBMS_XMLGEN.getXML(ctx);
    -- put data to host-file:
    vblob_len := DBMS_LOB.getlength(xmldoc);
    DBMS_LOB.READ (xmldoc, vblob_len, 1, vBuffer);
    bHandle := utl_file.fopen(vPATH,vFileName,'W',32767);
    UTL_FILE.put_line(bHandle, vbuffer, FALSE);
    UTL_FILE.fclose(bHandle);
    end ;
    maybe while work UTL_FILE there is a change the encoding ?
    How can this solved ?
    Thank you
    Norbert
    Edited by: astramare on Feb 11, 2009 12:39 PM with database charsets

    Marco,
    I tryed to work with dbms_xslprocessor.clob2file,
    that works good,
    but what is in this matter with encoding UTF-8 ?
    in my understandig, the xmltyp created should be UTF8 (16),
    but when open the xml-file in xmlSpy as UTF-8,
    it is not well ( german caracter like Ä, Ö .. ):
    my dbms is
    NLS_CHARACTERSET = WE8MSWIN1252
    NLS_NCHAR_CHARACTERSET = AL16UTF16
    NLS_RDBMS_VERSION = 10.2.0.1.0
    -- test:
    create table nh_test ( s0 number, s1 varchar2(20) ) ;
    insert into nh_test (select 1,'hallo' from dual );
    insert into nh_test (select 2,'straße' from dual );
    insert into nh_test (select 3,'mäckie' from dual );
    insert into nh_test (select 4,'euro_€' from dual );
    commit;
    select * from nh_test ;
    S0     S1
    1     hallo
    1     hallo
    2     straße
    3     mäckie
    4     euro_€
    declare
    rc sys_refcursor;
    begin
    open rc FOR SELECT * FROM ( SELECT s0,s1 from nh_test );
    dbms_xslprocessor.clob2file( xmltype( rc ).getclobval( ) , 'XML_EXPORT_DIR','my_xml_file.xml');
    end;
    ( its the same when using output with DBMS_XMLDOM.WRITETOFILE )
    open in xmlSpy is:
    <?xml version="1.0"?>
    <ROWSET>
    <ROW>
    <S0>1</S0>
    <S1>hallo</S1>
    </ROW>
    <ROW>
    <S0>2</S0>
    <S1>straޥ</S1>
    </ROW>
    <ROW>
    <S0>3</S0>
    <S1>m㢫ie</S1>
    </ROW>
    <ROW>
    <S0>4</S0>
    <S1>euro_€</S1>
    </ROW>
    </ROWSET>
    regards
    Norbert

  • Installing linux and unix on my macbook pro without using vmware

    I was browsing through the forum and bumped into a topic where the best advice for installing linux application is the following:
    http://macdevcenter.com/lpt/a/7073
    However, I have not tested this out therefore I am pretty reluctant to put this on my laptop which is currently running MAC OS X 10.5.8. (4gb ram). If anyone have done this please let me know.
    1) My question: Is this a reliable method to run linux applications on MAC OS natively using the x11 from Apple?
    Note: I have vmware and I personally don't prefer booting a separate OS on my computer just to use one or two apps. However if that is the only solution I already have ubuntu running on my vmware. Also I wanted to completely wipe off my vmware and the ISO images (ubuntu and win xp) to free up the space in my hard drive. If I have to use ubuntu which may be a "safer solution" than run linux applications on my hard drive then I will stick to the vmware method.
    If someone could give me some insight in this topic then I would greatly appreciated their help.
    p.s. I want to install xilinx web-pack and other useful softwares that are only available in linux, ubuntu and win xp/vista/w7. My goal is to completely transform my laptop from dual booting ubuntu and win xp to just run mac snow leopard (in the near future).
    Thanks in advance,
    Pirakalan S.
    Message was edited by: Pirakalan S.

    Basically I want to run linux and unix applications without running vmware on my mac os x. I heard there is a way to use x11 and FinkCommander (http://finkcommander.sourceforge.net/) application. However, I am unable to figure out how to install programs such as xilinx ise (http://www.xilinx.com/ise/logicdesignprod/foundation.htm) on my MacBook Pro using FinkCommander. In addition, xilinx ise runs on linux and windows however not mac.
    In simple words I want to solely use Leapord (not snow leapord) to run applications such xilinx ise (which is only available on windows platform or linux).
    I recently shifted from windows xp platform to mac and I rarely use vmware after making the shift. Therefore, I am trying to find a solution where I don't require vmware at all, my plan is to remove vmware from my hard drive.
    I just restated what I stated in the previous post in a simpler manner, sorry for any miscommunication on the earlier post. I am looking for a step by guide to install linux applications on my mac. I am at a process of learn linux at the moment so I am kind of slow when it comes to linux and mac. Especially when it comes to installing using command line not GUI.
    I just want to know if there is a solution out there for running linux based applications to run on my mac.

  • Our organization uses an Oracle database hosted on a Unix platform and one of our data processing outputs is a "stuffer" document that has a barcode, and Unix jobs automatically send the document to a printer.   Is there a way, or does Adobe have a produc

    Our organization uses an Oracle database hosted on a Unix platform and one of our data processing outputs is a “stuffer” document that has a barcode, and Unix jobs automatically send the document to a printer.
    Is there a way, or does Adobe have a product or solution, to create a PDF version of the document including the barcode, before it’s sent to a printer?

    What format is the document that is printed? Or what technology is used to format the printer? There isn't a standard way of doing things in Unix.

  • How to do an inbound and outbound interfacing using UTL_FILE ?

    dear members,
    How can we do interfacing from a legacy system to oracle and vice versa using the UTL_FILE package. I mean how to do an INBOUND and OUTBOUND interfacing using utl_file.
    regards
    sandeep

    in/
    file/
    bad/
    done/
    out/
    file/
    bad/
    done/
    I would start by ftping / putting the file in in/file/ folder, once ftp has completed move it to complete/ folder and process the file. If errorrs are generated move the file over to bad folder. If completed successfully move over to done folder.
    Having said that you would use UTL_FILE_DIR init parameter to set your directory.
    ALTER SYSTEM SET UTL_FILE_DIR='directory1','directory2' scope=spfile;
    Then you would use the regular utl_file packages to read / write to the files.
    UTL_FILE.FOPEN and so on.

  • How to do inbound and outbound interfacing using UTL_FILE?

    dear members,
    How can we do interfacing from a legacy system to oracle and vice versa using the UTL_FILE package. I mean how to do an INBOUND and OUTBOUND interfacing using utl_file.
    regards
    sandeep

    Hi Sandeep,
    I do not know if I got your question correct.
    Here is my understanding of it, pls correct me if I am wrong:
    You want to read from and write to the OS from inside the DB? Right?
    There are differnt waysa to do so, depanding on your Oracle version:
    1. you can use the initialization parameter UTL_FILE_DIR to specify a directory on OS where you can read from and write to through the package UTL_FILE.
    2. You can use a directory object in the DB to manage read write access to the OS. This is also usable with the package UTL_FILE as location where to read from and write to.
    => CREATE DIRECTORY my_dir AS '/home/oracle/my_directory';
    GRANT read , write ON DIRECTORY my_dir TO scott;
    SELECT * FROM dba_directories;
    You need CREATE ANY DIRECTORY system privilege for this.
    You can use directory objects also for external tables.
    With these you can read from flat files in teh directory on OS with a select statement as if it were a table inside the DB.
    Does this go into the direction you were thinking of?
    Hope it helps for the first.
    Regards,
    Lutz

  • How to find cd rom drive in windows and unix platform using java program

    Hi,
    I am having the requirement of finding the cd rom drive
    using java program. I do not know the label and which
    one is the cd rom drive. also I want to know how many
    cd rom drives are there on my system. I want the solution
    for windows and unix platforms.
    If have any suggestions please mail to [email protected]
    Deepak

    Ughhh.. I had the same problem with multi platform file-system detection
    First off - Unix.
    Do you know for sure you have all your drives mounted?? This could be a big problem because java will not see unmounted drives... So you can scour thru your /etc/fstab to find out which drives are available... or you can mount all and show roots... (Yuck!)... You've got timeouts and all sorts of things to worry about...
    I would then shy away from the java.io.File.listRoots() on unix and rely on parsing your fs file. If a user would like to see the medium in the drive. Do a Runtime.exec and mount the drive, then you can grab the filesystem by wrapping it in the java.io.File object. ( NOTE - this will hold well for your NFS mounts as well which might be buried under other FS. So you now have detection for that as well. ) Labels are also noted in this file. Let me know if you don't know the difference between mtab and fstab....
    Second - Winders.... Corney but I love saying that.
    The listRoots is a good solution. As others have said CD-ROMS will not be writable. Use a combination of getName and getPath to decipher the label and mount point.
    Hope this helps!

Maybe you are looking for

  • FCP Studio 3 install on Power Mac G5

    Anyone has tried to install the new FCP Studio 3 on a Power Mac G5 Quad computer? I have a PowerMac G5 Quad with FCP Studio 2 and want to find out wether I can upgrade to FCP Studio 3 or not? Thanks, r

  • Photo Folders on iPhone and iCloud

    Hello, I have my photos on my PC arranged by years in folders and sub-folders and I want to have them on my phone the exact same way AND have them saved to iCloud.  I spoke to tech support and they say this cant be done.  I would like to know if I ca

  • X2200 M2 iLom issue on OS X

    I can not seem to bring up the console through the web interface on a Mac running OS X. I can manage the server with the power-on, off, etc... Just not the console. I have tried both Safari and Firefox (1.5 & 2.0). On the Windows and Solaris (running

  • Error message when attempting to upload from Flip camera

    When attempting to download flip videos, I get a message stating that usb device was disabled because it was taking too much power from the computer. This just started suddenly.  I'd downloaded video from the same camera to this MacBookPro just the d

  • G530 Touch sensitive volume control panel

    After a quick reformat of my G530, the touch sensitive volume control panel (four black circular buttons in the upper right part above the keyboard) still works but the volume up/down buttons are in slow increments of 2% whereas before blue rectangul