Opening a STREAM in a Persistent Procedure Function

≡放荡痞女 提交于 2019-12-12 01:16:32

问题


I have a persistent procedure, in which I am trying to open, write and close a stream.

I have in the main area of the procedure

DEFINE STREAM sOutFile.
OPEN STREAM sOutFile TO VALUE( outFileName ).
MESSAGE SEEK( sOutFile ).

and subsequently a function within the persistent procedure

FUNCTION example RETURN LOGICAL:
  MESSAGE SEEK( sOutFile ).
  PUT STREAM sOutFile UNFORMATTED someData.
END.

When the persistent procedure is instantiated, the message displays "0" so the stream has been opened. However, when example is called, the message displays "?" and I get a message about attempting to write to a closed stream.

I've tried declaring the stream NEW SHARED but that didn't make any difference.

Am I doing something wrong, or is it impossible to define streams within persistent procedures?


回答1:


It is early and my coffee hasn't kicked in yet but I think that you have to open the stream outside the body of the PP.

This works:

/* ppstream.p
 *
 */

define stream logStream.

session:add-super-procedure( this-procedure ).

/* end of PP init */

function initLog returns logical ( input lgFile as character ):
  output stream logStream to value( lgFile ) unbuffered.
  return true.
end.

function logStuff returns logical ( input msg as character ):
  put stream logStream unformatted msg skip.
  return true.
end.

and then call it like so:

function initLog  returns logical ( input lgFile as character ) in super.
function logStuff returns logical ( input msg as character ) in super.

run ./ppstream.p persistent.

initLog( "log.txt" ).
logStuff( "test" ).

(I used a session super-procedure to avoid having to define handles -- you would not necessarily need to do that.)



来源:https://stackoverflow.com/questions/31289078/opening-a-stream-in-a-persistent-procedure-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!