Thread overview
portability note: newlines
Feb 10, 2005
Nick
February 10, 2005
Something that comes up time and time again
is forgetting to finish console output with
a newline character (either '\n' or using ln)

This is *not* portable, unfortunately...

On some systems, most notably Mac OS X,
the output must be "terminated" with a
newline character, or IT WILL NOT PRINT.

And that's independant of the language used:

> #!/bin/sh
> echo -n hello
> 
> #!/usr/bin/perl
> print "hello"
> 
> main()
> {
>   printf("hello");
> }
> 
> import std.stdio;
> void main(char[][] args)
> {
>   writef("hello");
> }

Each and everyone of these has same boring output:

# ./a.out
#

On other systems, such as Linux, they instead show:

# ./a.out
hello#

So, if you want Mac users to read your msg too, use:

> #!/bin/sh
> echo hello
> 
> #!/usr/bin/perl
> print "hello\n"
> 
> main()
> {
>   printf("hello\n");
> }
> 
> import std.stdio;
> void main(char[][] args)
> {
>   writefln("hello");
> }

Thanks for listening... And _please_ change your code.

--anders

PS. I've already reported a bug against "sieve.d"...
    It doesn't find any primes on Mac OS X, because
    it forgets to add a "\n" newline after the printf.

February 10, 2005
In article <cufbpq$1j8e$1@digitaldaemon.com>, =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= says...
>
>Each and everyone of these has same boring output:
>
># ./a.out
>#
>
>On other systems, such as Linux, they instead show:
>
># ./a.out
>hello#

Just a comment: there isn't any consistent behaviour in linux. On the tty console or over shh, I get

$ echo -n hello
hello$

but on an xterm there is no output.


February 10, 2005
Nick wrote:

> Just a comment: there isn't any consistent behaviour in linux. On the
> tty console or over shh, I get
> 
> $ echo -n hello
> hello$
> 
> but on an xterm there is no output.

Moral of the story: always use explicit newlines :-)

As a side note, the programs do still output something
so if you pipe it to something else it still shows up...

Just that nothing is displayed to the user on the console.

--anders