Published on InterSystems Developer Community (https://community.intersystems.com)

Home > Cache Studio freezes on line Use $io::("^"_$ZNAME)

Question
Mihai Radu · Aug 31, 2017

Cache Studio freezes on line Use $io::("^"_$ZNAME)

I am trying to capture the write of a method to test the response in an unit test. I know everything works because one of my colleagues ran the code and did not froze on his machine.

I don't what is the cause of the freeze. I know that at line Use $io::("^"_$ZNAME) it stopes because i have put some write functions after every line in WriteCapture method and i only saw the first write function in terminal

I also used debug and in this case it didn't froze

PS: forgot to put the status in the XECUTE (vstrCommand , .status)

This is my method that captures the write:

 ClassMethod WriteCapture(vstrCommand As %String, Output strOutput As %String, Output status As %Status) [ ProcedureBlock = 0 ]
{
 
//Redirect IO to the current routine - makes use of the labels defined below
    Use $io::("^"_$ZNAME)
    //Enable redirection
    Do ##class(%Device).ReDirectIO(1)
Try
{
XECUTE (vstrCommand , .status)
}
Catch ex
{
//Set st = ex.AsStatus()
//w "st = " _ st
WRITE "Name: ",$ZCVT(ex.Name,"O","HTML"),!
}
  
    //Disable redirection
    Do ##class(%Device).ReDirectIO(0)
    //Labels that allow for IO redirection
    //Read Character - we don't care about reading
rchr(c) quit
    //Read a string - we don't care about reading
rstr(sz,to) quit
    //Write a character - call the output label
wchr(s) do output($char(s)) quit
    //Write a form feed - call the output label
wff() do output($char(12)) quit
    //Write a newline - call the output label
wnl() do output($char(13,10)) quit
    //Write a string - call the output label
wstr(s) do output(s) quit
    //Write a tab - call the output label
wtab(s) do output($char(9)) quit
    //Output label - this is where you would handle what you actually want to do.
    // in our case, we want to write to myStr. myStream commented out.
    // do myStream.Write(s) 
output(s) set strOutput =strOutput_s quit
}

 and this i where i call it :

 ClassMethod TestGetAllChats2()
{
#Dim strOutput As %String
#Dim status As %Status = $$$OK
Set strOutput = ""

Set strCmd = "(status) Set status = $CLASSMETHOD(""Apps.Apo.ChefApp.ChatInfo.ChatModule"",""GetDifferencesAllChats"",""1"",""5"", 1)"
w !, "strCmd = " _strCmd


    Do ##class(Apps.Apo.Miscellaneous.Helper).WriteCapture(strCmd, .strOutput, .status)
    w strOutput
}
#Beginner #Studio #Terminal #Testing #Caché

Source URL:https://community.intersystems.com/post/cache-studio-freezes-line-use-iozname