Re: [S] command window & printf

Prof Brian Ripley (
Wed, 4 Mar 1998 07:56:56 +0000 (GMT)

David Butler wrote:
> Dear all,
> I am working with an iterative procedure written in Fortran (& c) and
> called from an S+ function. I would like information from each
> iteration to be written from within the external procedure to the S+
> command window, or even better, to a separate window.
> The procedures currently run on both UNIX (SUN Solaris) and
> Splus4/Win95 platforms. I can print to the S+ command window on the
> SUN by calling c from Fortran and using the standard printf function,
> however, while the same code runs on Win95 it produces no output.
> Does anybody know:
> (a) if it is possible to write to the command window from c in
> S+4/Win95

Yes. S-PLUS 4.0 comes with release notes, and you do need to read them.
Alternatively, read the on-line complements to V&R2 (via my web page)
which say:

There is a problem with the use of the usual I/O using stdin,
stdout and stderr using S-PLUS 4.0 under Windows. To
work around this portably, include the following in your C code

#include <S.h>
#if defined(SPLUS_VERSION) && SPLUS_VERSION >= 4000
# include <newredef.h>

Without this, the I/O is delayed or lost. Further, scanf
cannot be used; use fgets and sscanf instead.

If you follow this, the same code will compile and work under each of Unix
and Windows. I was advised this will probably be needed in all future
versions of S-PLUS, hence the test on version number.

> (b) how one might open a separate window in both UNIX & Win95
> to write into.

Doing this in both will be very difficult! Assuming you meant `each', the
solutions will be quite different in each case. Under Solaris I would
probably launch a command window or xterm with a process listening on a
named pipe, and write output to that pipe. Under Windows you can open a
window with Windows API calls or launch a process and communicate via
DDE or OLE automation, but the easiest way is probably just to use a
results window. There are GUI commands to switch output to a results
window, and I suggest you investigate those. If you have a bunch of
output to put up in a separate window in one go, look at page().

BTW, C _is_ capitalized.

Brian D. Ripley,        
Professor of Applied Statistics,
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595
This message was distributed by  To unsubscribe
send e-mail to with the BODY of the
message:  unsubscribe s-news