Question
· Nov 9, 2017

Is There way to write to a text file direct without Stream

I am using a %GlobalStream to create as % stream.Object and writing that to a file but for some reason when I run that on the terminal I get <PARAMETER>zWrite^%Library.GlobalCharacterStream.1 and no file is created

I have tried the following here is my code and still get the same result  any help  appreciated

ClassMethod WriteNodes(myfile As %String)
{
  set status=##class(%XML.TextReader).ParseFile(myfile,.textreader)

  set ptemp=##class(%GlobalCharacterStream).%New()
  //check status
  if $$$ISERR(status) {do $System.Status.DisplayError(status) quit}
  //iterate through document, node by node
  while textreader.Read()
  {
    Do ptemp.Write("Node ", textreader.seq, " is a(n) ")
    Do ptemp.Write( textreader.NodeType," ")
    If textreader.Name'=""
    {
      Do ptemp.Write( "named: ", textreader.Name)
    }
    Else
    {
      Do ptemp.Write( "and has no name")
    }
    Do ptemp.Write( " path: ",textreader.Path)
    If textreader.Value'="" 
    {
      Do ptemp.Write( " value: ", textreader.Value)
    }
  }

  set adapter = ##class(%File).%New("C:\IT\50_TestIn\warddata1.txt")
  set status = adapter.Write(ptemp)
      /* set tStream=##class(%Stream.FileCharacter).%New()
        set pInput=##class(%Stream.Object).%New()
        set pInput=ptemp
         set ptemp=""
         
        set myfile="C:\IT\50_TestIn\warddata1.txt"
        
        Set tStatus =tStream.LinkToFile("Myfile")
        
        do tStream.Write(pInput)
         
         */
} 
Discussion (5)1
Log in or sign up to continue

The following corrected code works for me:

ClassMethod WriteNodes(myfile As %String)
{
  set status=##class(%XML.TextReader).ParseFile(myfile,.textreader)
  if $$$ISERR(status{do $System.Status.DisplayError(statusquit}

  set ptemp=##class(%Stream.FileCharacter).%New()
  set ptemp.Filename="C:\IT\50_TestIn\warddata1.txt"
  //check status
  //iterate through document, node by node
  while textreader.Read()
  {
    Do ptemp.Write("Node " textreader.seq " is a(n) ")
    Do ptemp.Write(textreader.NodeType " ")
    If textreader.Name'=""
    {
      Do ptemp.Write"named: "textreader.Name)
    }
    Else
    {
      Do ptemp.Write"and has no name")
    }
    Do ptemp.Write" path: " textreader.Path)
    If textreader.Value'="" 
    {
      Do ptemp.Write" value: " textreader.Value)
    }
    Do ptemp.WriteLine()
  }

  Do ptemp.%Save()
}