1
\$\begingroup\$

This question already has an answer here:

Introduction

Everyone's first program outputs Hello World!. This program should be very simple, that's all you have to do.

Challenge

Output the string Hello World! to the STDERR.

Rules

  1. If your language doesn't support STDERR or STDERR doesn't exist for it, you can output it to it's corresponding error system.
  2. You can't output anything else to STDERR except for Hello World!.
  3. You can't output anything to STDOUT or take any input from STDIN
  4. You can't read any content from files.

This is , so the shortest answer in bytes wins.

\$\endgroup\$

marked as duplicate by a spaghetto, wizzwizz4, GamrCorps, Justin, Alex A. code-golf Jan 25 '16 at 0:30

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 3
    \$\begingroup\$ PHP has stderr. \$\endgroup\$ – Keelan Jan 24 '16 at 21:57
  • 5
    \$\begingroup\$ @Mego I personally don't think it's a duplicate. Seeing as how the output method is required to be different, programs cannot just be stolen from that challenge. \$\endgroup\$ – ETHproductions Jan 24 '16 at 22:15
  • 2
    \$\begingroup\$ @ETHproductions IMO the different output method (STDERR vs STDOUT) isn't sufficiently different enough to make it not a dupe. Most of the answers could be trivially transformed by writing to STDERR or file stream 1 instead of STDOUT. \$\endgroup\$ – Mego Jan 24 '16 at 22:16
  • 1
    \$\begingroup\$ I agree with @Mego and therefore closed this as duplicate, not unclear (despite what the banner says). The question is not unclear by any stretch of the imagination. \$\endgroup\$ – mınxomaτ Jan 24 '16 at 22:32
  • 9
    \$\begingroup\$ Note: The comma in Hello, World! is not necessary. Please do yourself a favor and save a byte. \$\endgroup\$ – ETHproductions Jan 24 '16 at 22:59

31 Answers 31

6
\$\begingroup\$

Japt, 17 bytes

Currently winning! Let's hope Jelly doesn't pop in with an 11-byte answer...

Ox`È*w'HÁM W?ld!'

The ? should be the literal byte 8E. Test it online!

(STDERR is found below the "Upload a file" line in red text.)

How it works

  `È*w'HÁM W?ld!'  // Decompress this string. Returns "throw'Hello World!'"
Ox                 // Evaluate as JavaScript code. Throws the error.
                   // Implicit: Error is caught by interpreter and sent to STDERR.

Alternate version:

$throw$`HÁM W?ld!
\$\endgroup\$
  • 2
    \$\begingroup\$ Ham World? :P \$\endgroup\$ – Downgoat Jan 25 '16 at 2:13
  • 4
    \$\begingroup\$ @Doᴡɴɢᴏᴀᴛ ew ham world. Or should I say "È*w"? \$\endgroup\$ – Cyoce Jan 25 '16 at 6:38
8
\$\begingroup\$

zsh, 21 20 19 bytes

<<<Hello\ World!>&2

This is a zsh-specific feature; won't work in bash.

Thanks to @FlagAsSpam and @Dennis for a byte each!

\$\endgroup\$
5
\$\begingroup\$

JavaScript, 30 bytes

console.error("Hello, World!")

An alternative JavaScript answer, using console.error.

\$\endgroup\$
4
\$\begingroup\$

Java 8, 75 37 bytes

Thanks to @GamrCorps for slicing the code size almost exactly in half and showing me how to use lambda!

()->System.err.print("Hello World!");

Using interface because it makes the main declaration shorter. c:

\$\endgroup\$
  • \$\begingroup\$ darn it, you beat me to it! \$\endgroup\$ – GamrCorps Jan 24 '16 at 22:02
  • 1
    \$\begingroup\$ Hint: Java 8 and use a lambda \$\endgroup\$ – GamrCorps Jan 24 '16 at 22:03
  • 2
    \$\begingroup\$ @feersum I think we by default allow functions unless the question says "full program". \$\endgroup\$ – lirtosiast Jan 24 '16 at 22:06
  • 1
    \$\begingroup\$ @FlagAsSpam ()->System.err.print("Hello, World!"); should work \$\endgroup\$ – GamrCorps Jan 24 '16 at 22:12
  • 2
    \$\begingroup\$ Why the down vote? \$\endgroup\$ – Addison Crump Jan 24 '16 at 23:17
4
\$\begingroup\$

JavaScript, 19 bytes

throw"Hello World!"

Yes. It's that simple. Try it in the browser console on any page.

\$\endgroup\$
  • \$\begingroup\$ Would using bota be shorter (ie throw bota`Base64 String Here`)? idk, i haven't tried it. \$\endgroup\$ – MayorMonty Jan 24 '16 at 22:09
  • \$\begingroup\$ @SpeedyNinja No, the ! and space will each cause an error if you try to compress it. It wouldn't be worth it anyway. \$\endgroup\$ – ETHproductions Jan 24 '16 at 22:09
  • 1
    \$\begingroup\$ Oh ASCII, you're so helpless, ;) \$\endgroup\$ – MayorMonty Jan 24 '16 at 22:10
  • 2
    \$\begingroup\$ whyyy doncha adda stack snippet!? :P \$\endgroup\$ – cat Jan 24 '16 at 22:57
  • 2
    \$\begingroup\$ @cat It doesn't really work with a stack snippet, outputting instead uncaught exception: Hello World! to an error in the console. \$\endgroup\$ – ETHproductions Jan 24 '16 at 23:02
4
\$\begingroup\$

C, 35 bytes

main(){write(2,"Hello World!",12);}

write writes to a file descriptor. STDERR is file descriptor 2, and 12 is the length of the string "Hello World!".

\$\endgroup\$
3
\$\begingroup\$

AutoIt, 33 bytes

ConsoleWriteError("Hello World!")
\$\endgroup\$
3
\$\begingroup\$

R, 23 bytes

message("Hello World!")

The message function writes to STDERR.

\$\endgroup\$
3
\$\begingroup\$

Ruby, 18 bytes

warn"Hello World!"

This only works if warnings are on (which is the default).

\$\endgroup\$
  • \$\begingroup\$ Works for me with irb. \$\endgroup\$ – Mego Jan 24 '16 at 22:23
3
\$\begingroup\$

C++, 53 bytes

#include<iostream>
main(){std::cerr<<"Hello World!";}

You can try it online if you feel so inclined.

\$\endgroup\$
3
\$\begingroup\$

Python 2, 36 bytes

import os
os.write(2,'Hello World!')

Despite being based on a Unix syscall, this works as well on Windows.

\$\endgroup\$
3
\$\begingroup\$

Bash, 24 21 20 bytes

Saved 3 bytes thanks to @Neil, then another from @Dennis!

echo Hello World!>&2 

>&2 pushes the output to STDERR.

\$\endgroup\$
  • \$\begingroup\$ Drop the comma, use backslash to quote the !, and move the >&2 to the end without the space, to save 3 bytes. \$\endgroup\$ – Neil Jan 24 '16 at 22:32
  • 1
    \$\begingroup\$ Escaping the exclamation point is not required inside a script. \$\endgroup\$ – Dennis Jan 24 '16 at 22:33
3
\$\begingroup\$

Rust, 73 72 bytes

use std::io::Write;fn main(){std::io::stderr().write(b"Hello, World!");}

Rust is as long as ever...

Thanks to @ICanHazHats for saving a byte!

\$\endgroup\$
  • \$\begingroup\$ use std::io::Write;fn main(){std::io::stderr().write(b"Hello, World!");} is 72 bytes and is working with Rust 1.3 (I don't know how outdated that is) \$\endgroup\$ – Liam Jan 24 '16 at 23:10
  • \$\begingroup\$ @ICanHazHats That does work on the nightly. Thanks! \$\endgroup\$ – Doorknob Jan 24 '16 at 23:12
  • \$\begingroup\$ Don't thank me, I yanked it straight from stackoverflow stackoverflow.com/questions/27588416/… \$\endgroup\$ – Liam Jan 24 '16 at 23:14
  • \$\begingroup\$ These days you can write fn main(){eprint!("Hello, World!")}, but not that it matters as this challenge is closed. \$\endgroup\$ – Konrad Borowski Jul 5 '18 at 4:43
3
\$\begingroup\$

Matlab, 21 bytes

error('Hello World!')
\$\endgroup\$
2
\$\begingroup\$

Julia, 28 bytes

print(STDERR,"Hello World!")

Does what it looks like it does. STDERR is a built-in constant that refers to the standard error stream and print takes an optional argument specifying the stream.

Note that using error() prints out a bunch of extra garbage.

\$\endgroup\$
2
\$\begingroup\$

AppleScript, 19 bytes

error"Hello World!"

...pretty self-explanatory.

\$\endgroup\$
  • 2
    \$\begingroup\$ Like AppleScript always is. \$\endgroup\$ – Elliot A. Jan 25 '16 at 0:46
  • \$\begingroup\$ @ElliotA. Amen. \$\endgroup\$ – Addison Crump Jan 25 '16 at 0:49
2
\$\begingroup\$

PHP, 36 bytes

I don't know much PHP, but here goes...

<?php fwrite(STDERR,"Hello World!");

Tested on ideone.com.

\$\endgroup\$
2
\$\begingroup\$

Chapel, 29 bytes

stderr.write("Hello World!");

This language is probably overkill.

\$\endgroup\$
  • \$\begingroup\$ This language is overkill, unless you have a SuperComputer. Do you have a supercomputer, Phi? \$\endgroup\$ – cat Jan 24 '16 at 22:56
  • \$\begingroup\$ @cat "The only supercomputer I have is my mind." (As a serious answer, no, I just put Chapel on my laptop.) \$\endgroup\$ – PhiNotPi Jan 24 '16 at 23:14
  • \$\begingroup\$ You shoulda used multithreading for this answer. One thread per character of output, because why not!? \$\endgroup\$ – cat Jan 24 '16 at 23:15
2
\$\begingroup\$

Python 3, 33 bytes

open(2,'w').write('Hello World!')
\$\endgroup\$
  • \$\begingroup\$ which py3 version are you running this on? When I try this I get an invalid handle error. (on second thoughts, it's more likely an OS problem) \$\endgroup\$ – FlipTack Dec 13 '16 at 23:09
  • \$\begingroup\$ @Flp.Tkc It works on both Linux and Windows for me. The stderr = 2 is a feature from Unix, but Python developers ported this special case to Windows. \$\endgroup\$ – feersum Dec 13 '16 at 23:35
2
\$\begingroup\$

C#, 95 bytes

using System;class M{public static void Main(string[]a){Console.Error.Write("Hello World!");}}

I'm trying to learn this langauge but god, it's verbose.

Ungolfed:

using System;

class MainClass {
    public static void Main (string[] args) {
        Console.Error.Write ("Hello World!");
    }
}
\$\endgroup\$
  • 2
    \$\begingroup\$ Congrats on exactly 1k rep! \$\endgroup\$ – ETHproductions Jan 24 '16 at 23:39
  • \$\begingroup\$ @ETHproductions thanks! I previously had 1.2k but then I gave a bounty for an answer in SPL :P \$\endgroup\$ – cat Jan 24 '16 at 23:46
1
\$\begingroup\$

Pascal (FP/GP), 51 bytes

program h;begin writeln(StdErr,'Hello World!');end.
\$\endgroup\$
1
\$\begingroup\$

Pike, 35 bytes

int main(){werror("Hello World!");}

Looks like C, isn't C. Is interpreted.


We can make this compile as ANSI C like this:

#include <stdio.h>
# ifndef __PIKE__
#   define werror(x) fputs(x, stderr)
# endif

int main() {
  werror("Hello World!");
}
\$\endgroup\$
  • 1
    \$\begingroup\$ I count 35 bytes... \$\endgroup\$ – Addison Crump Jan 24 '16 at 23:03
  • \$\begingroup\$ @FlagAsSpam I can count today!! \$\endgroup\$ – cat Jan 24 '16 at 23:11
1
\$\begingroup\$

Perl, 25 24 bytes

say stderr"Hello World!"

Requires version 5.10 or later.

Thanks to @FlagAsSpam for a byte!

\$\endgroup\$
  • \$\begingroup\$ Can you remove the space in stderr "Hello World!" (drop the comma). \$\endgroup\$ – Addison Crump Jan 24 '16 at 23:09
  • \$\begingroup\$ Well, I got ninja'd! \$\endgroup\$ – cat Jan 24 '16 at 23:09
  • \$\begingroup\$ @FlagAsSpam Nope. (This time for real.) \$\endgroup\$ – Doorknob Jan 24 '16 at 23:10
  • \$\begingroup\$ Hmm. It's really weird - some languages parse " as a parenthetical as well, allowing for some interesting stuff (notably in return""). I just generally put that down, now, because it's a lot of langs that have that. \$\endgroup\$ – Addison Crump Jan 24 '16 at 23:11
  • 1
    \$\begingroup\$ Actually, you can remove the space (tested on perl 5.18.2). \$\endgroup\$ – Addison Crump Jan 24 '16 at 23:13
1
\$\begingroup\$

Forth, 65 bytes

Shorter than factor!

outfile-id stderr to outfile-id ." Hello World!" cr to outfile-id
\$\endgroup\$
1
\$\begingroup\$

Moonscript, 40 bytes

io.stderr.write io.stderr,"Hello World!"

CoffeeScript for Lua... because Lua is ugly as hell!

\$\endgroup\$
1
\$\begingroup\$

Lua5.2, 41 bytes

io.stderr.write(io.stderr,"Hello World!")

Cheeky golfed version of the transpilation of my Moonscript answer.

\$\endgroup\$
0
\$\begingroup\$

Go, 39 38 37 70 69 bytes

package m;import."os";func main(){Stderr.WriteString("Hello World!")}
\$\endgroup\$
  • \$\begingroup\$ This is 37 bytes. \$\endgroup\$ – Addison Crump Jan 24 '16 at 22:29
  • \$\begingroup\$ @FlagAsSpam I forgot there was a trailing space, oops! The spec really isn't clear on whether I can give a snippet (this) or a full program -- the C++ one is a full program, this isn't, but it's not said. \$\endgroup\$ – cat Jan 24 '16 at 22:32
  • 2
    \$\begingroup\$ Snippets are never a valid form of answer. Usually programs or functions are, but the question asks for a program. \$\endgroup\$ – feersum Jan 24 '16 at 22:33
  • \$\begingroup\$ @feersum you're right, but it's only mentioned offhandedly, not in the actual spec list. \$\endgroup\$ – cat Jan 24 '16 at 22:34
  • 1
    \$\begingroup\$ Drop the comma. \$\endgroup\$ – Addison Crump Jan 24 '16 at 22:38
0
\$\begingroup\$

Mathematica, 35 bytes

"stderr"~WriteString~"Hello World!"

Quite simple.

\$\endgroup\$
  • \$\begingroup\$ This doesn't output an error message. I think you need to use Message. Anyway, messages appear in red font so as to be easily distinguished from output. \$\endgroup\$ – DavidC Jan 25 '16 at 0:08
  • \$\begingroup\$ @DavidC Run this as a script. \$\endgroup\$ – LegionMammal978 Jan 25 '16 at 0:53
  • \$\begingroup\$ I do not know what a script is. \$\endgroup\$ – DavidC Jan 25 '16 at 3:32
  • \$\begingroup\$ @DavidC Just put the code in a file, and run MathematicaScript -script <file>. \$\endgroup\$ – LegionMammal978 Jan 25 '16 at 11:41
0
\$\begingroup\$

Microsoft Windows Batch (also works in Wine), 22 bytes

echo Hello World! 1>&2
\$\endgroup\$
0
\$\begingroup\$

Factor, 67 bytes

"Let's use a modernisation of Forth", I said. "It will be fun!" I said.

Yea, the whitespace is needed.

error-stream get [ "Hello World!" print flush ] with-output-stream*
\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.