User bio
404 bio not found
Member since Nov 9, 2015
Replies:

Using a device mnemonic routine and redirecting IO also seems to work. I used this very basic routine to log to IO:

ZJES01	;
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 str
output(s) set ^ZJES($increment(^ZJES))=s quit

And then used the following classmethod to test:

ClassMethod TestRedirect()
{
	
	set MnemonicRoutine = ##class(%Device).GetMnemonicRoutine()
	use $io::("^ZJES01")
	set RedirectIO=##class(%Device).ReDirectIO(1)
	do ..PythonPrint()
	do ##class(%Device).ReDirectIO(RedirectIO)
	use $io::("^"_MnemonicRoutine)
	quit
}

Which gave me:

zwrite ^ZJES
^ZJES=3
^ZJES(1)="Python print this line to the buffer"
^ZJES(2)=$c(13,10)
^ZJES(3)="IRIS write this line to the buffer"

How is the buffer class capturing the output? I did a very quick testing using the spool device and a USE statement and the output appeared in ^SPOOL as expected:

/// Open spool device and call Embedded Python method.
ClassMethod TestSpool()
{
	set SpoolFile = $order(^SPOOL(""),-1)+1
	open 2:SpoolFile
	use 2
	do ..PythonPrint()
	close 2
	break
}

ClassMethod PythonPrint() [ Language = python ]
{
	import iris 
	print("Python print this line to the buffer")
	iris.execute('write "IRIS write this line to the buffer"')
}
zwrite SpoolFile
SpoolFile=956

zwrite ^SPOOL(956)
^SPOOL(956,1)="Python print this line to the buffer"_$c(10)
^SPOOL(956,2)="IRIS write this line to the buffer"
^SPOOL(956,2147483647)="{67424,57942{3{"

You can use the SQL DATEDIFF function in ObjectScript to get the number of minutes and divide by 60:

write $system.SQL.Functions.DATEDIFF("mi","2024-07-12 08:30:00","2024-07-12 15:15:00")/60  
6.75

Documentation is here: https://docs.intersystems.com/iris20252/csp/documatic/%25CSP.Documatic.c...

You can pass "hh" in as the first argument to get hours, but only returns whole hours rounded up. If you need second accuracy, you can pass in "ss" for "seconds" and divide by 3600 instead.

Certifications & Credly badges:
Jolyon has no Certifications & Credly badges yet.
Global Masters badges:
Jolyon has no Global Masters badges yet.
Followers:
Jolyon has no followers yet.
Following:
Jolyon has not followed anybody yet.