@@ -1696,13 +1696,15 @@ class Write(Builtin):
16961696 def apply (self , channel , expr , evaluation ):
16971697 "Write[channel_, expr___]"
16981698
1699- strm = channel_to_stream (channel )
1699+ stream = None
1700+ if isinstance (channel , String ):
1701+ stream = {"stdout" : 1 , "stderr" : 2 }.get (channel .value , None )
17001702
1701- if strm is None :
1702- return
1703-
1704- n = strm . elements [ 1 ]. get_int_value ()
1705- stream = stream_manager .lookup_stream (n )
1703+ if stream is None :
1704+ strm = channel_to_stream ( channel , "w" )
1705+ if strm is None :
1706+ return
1707+ stream = stream_manager .lookup_stream (strm . elements [ 1 ]. get_int_value () )
17061708
17071709 if stream is None or stream .io is None or stream .io .closed :
17081710 evaluation .message ("General" , "openx" , channel )
@@ -1763,6 +1765,9 @@ class WriteString(Builtin):
17631765 #> DeleteFile[pathname];
17641766 #> Clear[pathname];
17651767
1768+
1769+ If stream is the string "stdout" or "stderr", writes to the system standard output/ standard error channel:
1770+ >> WriteString["stdout", "Hola"]
17661771 """
17671772
17681773 summary_text = "write a sequence of strings to a stream, with no extra newlines"
@@ -1773,12 +1778,18 @@ class WriteString(Builtin):
17731778
17741779 def apply (self , channel , expr , evaluation ):
17751780 "WriteString[channel_, expr___]"
1776- strm = channel_to_stream (channel , "w" )
1777-
1778- if strm is None :
1779- return
1780-
1781- stream = stream_manager .lookup_stream (strm .elements [1 ].get_int_value ())
1781+ stream = None
1782+ if isinstance (channel , String ):
1783+ if channel .value == "stdout" :
1784+ stream = stream_manager .lookup_stream (1 )
1785+ elif channel .value == "stderr" :
1786+ stream = stream_manager .lookup_stream (2 )
1787+
1788+ if stream is None :
1789+ strm = channel_to_stream (channel , "w" )
1790+ if strm is None :
1791+ return
1792+ stream = stream_manager .lookup_stream (strm .elements [1 ].get_int_value ())
17821793
17831794 if stream is None or stream .io is None or stream .io .closed :
17841795 return None
0 commit comments