HelloWorld error

1

2

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.

Elliot A.

Posted 2016-01-24T21:56:00.370

Reputation: 456

Question was closed 2016-01-25T00:30:58.403

3PHP has stderr. – None – 2016-01-24T21:57:04.603

5@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. – ETHproductions – 2016-01-24T22:15:02.073

2@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. – Mego – 2016-01-24T22:16:27.520

I'd tend to agree with @Mego. The distinction of writing to STDERR versus STDOUT is pretty trivial in the majority of languages. – Alex A. – 2016-01-24T22:16:33.123

1I 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. – mınxomaτ – 2016-01-24T22:32:16.193

*four* reopen votes!? – cat – 2016-01-24T22:36:52.937

1@cat 5, actually. :P – Addison Crump – 2016-01-24T22:38:43.013

9Note: The comma in Hello, World! is not necessary. Please do yourself a favor and save a byte. – ETHproductions – 2016-01-24T22:59:30.120

1Relevant RosettaCode. – cat – 2016-01-24T23:21:50.010

@Mego This question's point is about outputting to STDERR. I've seen that Hello World question, and this isn't a copy. – Elliot A. – 2016-01-25T01:20:31.450

@ElliotA. Just outputting something to STDERR is too trivial. Outputting Hello, World! (or any simple variant thereof) is a dupe. Combining those two pieces doesn't make for a good challenge. – Mego – 2016-01-25T01:48:15.410

Answers

6

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!

ETHproductions

Posted 2016-01-24T21:56:00.370

Reputation: 47 880

2Ham World? :P – Downgoat – 2016-01-25T02:13:19.463

4@Doᴡɴɢᴏᴀᴛ ew ham world. Or should I say "È*w"? – Cyoce – 2016-01-25T06:38:13.660

8

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!

Doorknob

Posted 2016-01-24T21:56:00.370

Reputation: 68 138

5

JavaScript, 30 bytes

console.error("Hello, World!")

An alternative JavaScript answer, using console.error.

Conor O'Brien

Posted 2016-01-24T21:56:00.370

Reputation: 36 228

4

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:

Addison Crump

Posted 2016-01-24T21:56:00.370

Reputation: 10 763

darn it, you beat me to it! – GamrCorps – 2016-01-24T22:02:24.157

@GamrCorps Booyah. – Addison Crump – 2016-01-24T22:03:04.003

1Hint: Java 8 and use a lambda – GamrCorps – 2016-01-24T22:03:19.870

This isn't a full program. – feersum – 2016-01-24T22:03:52.563

2@feersum I think we by default allow functions unless the question says "full program". – lirtosiast – 2016-01-24T22:06:17.127

@ThomasKwa It says "everybody's first program..." Should I make it a program, or no? – Addison Crump – 2016-01-24T22:07:44.673

@FlagAsSpam It's not "full program", so no. – lirtosiast – 2016-01-24T22:08:35.970

@GamrCorps What's the lambda syntax, again? – Addison Crump – 2016-01-24T22:10:52.603

1@FlagAsSpam ()->System.err.print("Hello, World!"); should work – GamrCorps – 2016-01-24T22:12:39.273

2Why the down vote? – Addison Crump – 2016-01-24T23:17:28.480

4

JavaScript, 19 bytes

throw"Hello World!"

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

ETHproductions

Posted 2016-01-24T21:56:00.370

Reputation: 47 880

Would using bota be shorter (ie throw bota\Base64 String Here``)? idk, i haven't tried it. – MayorMonty – 2016-01-24T22:09:10.690

@SpeedyNinja No, the ! and space will each cause an error if you try to compress it. It wouldn't be worth it anyway. – ETHproductions – 2016-01-24T22:09:51.763

1Oh ASCII, you're so helpless, ;) – MayorMonty – 2016-01-24T22:10:28.247

2whyyy doncha adda stack snippet!? :P – cat – 2016-01-24T22:57:17.557

2@cat It doesn't really work with a stack snippet, outputting instead uncaught exception: Hello World! to an error in the console. – ETHproductions – 2016-01-24T23:02:41.457

4

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!".

Doorknob

Posted 2016-01-24T21:56:00.370

Reputation: 68 138

3

AutoIt, 33 bytes

ConsoleWriteError("Hello World!")

mınxomaτ

Posted 2016-01-24T21:56:00.370

Reputation: 7 398

3

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.

Addison Crump

Posted 2016-01-24T21:56:00.370

Reputation: 10 763

Drop the comma, use backslash to quote the !, and move the >&2 to the end without the space, to save 3 bytes. – Neil – 2016-01-24T22:32:02.520

1Escaping the exclamation point is not required inside a script. – Dennis – 2016-01-24T22:33:06.033

3

Python 2, 36 bytes

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

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

feersum

Posted 2016-01-24T21:56:00.370

Reputation: 29 566

3

Matlab, 21 bytes

error('Hello World!')

flawr

Posted 2016-01-24T21:56:00.370

Reputation: 40 560

3

R, 23 bytes

message("Hello World!")

The message function writes to STDERR.

Alex A.

Posted 2016-01-24T21:56:00.370

Reputation: 23 761

3

Ruby, 18 bytes

warn"Hello World!"

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

lirtosiast

Posted 2016-01-24T21:56:00.370

Reputation: 20 331

Works for me with irb. – Mego – 2016-01-24T22:23:09.833

3

C++, 53 bytes

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

You can try it online if you feel so inclined.

Alex A.

Posted 2016-01-24T21:56:00.370

Reputation: 23 761

3

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!

Doorknob

Posted 2016-01-24T21:56:00.370

Reputation: 68 138

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) – Liam – 2016-01-24T23:10:08.607

@ICanHazHats That does work on the nightly. Thanks! – Doorknob – 2016-01-24T23:12:55.803

Don't thank me, I yanked it straight from stackoverflow http://stackoverflow.com/questions/27588416/how-to-send-output-to-stderr

– Liam – 2016-01-24T23:14:05.247

These days you can write fn main(){eprint!("Hello, World!")}, but not that it matters as this challenge is closed. – Konrad Borowski – 2018-07-05T04:43:04.707

2

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.

Alex A.

Posted 2016-01-24T21:56:00.370

Reputation: 23 761

2

AppleScript, 19 bytes

error"Hello World!"

...pretty self-explanatory.

Addison Crump

Posted 2016-01-24T21:56:00.370

Reputation: 10 763

2Like AppleScript always is. – Elliot A. – 2016-01-25T00:46:14.420

@ElliotA. Amen. – Addison Crump – 2016-01-25T00:49:02.137

2

PHP, 36 bytes

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

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

Tested on ideone.com.

ETHproductions

Posted 2016-01-24T21:56:00.370

Reputation: 47 880

2

Chapel, 29 bytes

stderr.write("Hello World!");

This language is probably overkill.

PhiNotPi

Posted 2016-01-24T21:56:00.370

Reputation: 26 739

This language is overkill, unless you have a SuperComputer. Do you have a supercomputer, Phi? – cat – 2016-01-24T22:56:14.470

@cat "The only supercomputer I have is my mind." (As a serious answer, no, I just put Chapel on my laptop.) – PhiNotPi – 2016-01-24T23:14:34.887

You shoulda used multithreading for this answer. One thread per character of output, because why not!? – cat – 2016-01-24T23:15:28.507

2

Python 3, 33 bytes

open(2,'w').write('Hello World!')

feersum

Posted 2016-01-24T21:56:00.370

Reputation: 29 566

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) – FlipTack – 2016-12-13T23:09:00.683

@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. – feersum – 2016-12-13T23:35:55.883

2

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!");
    }
}

cat

Posted 2016-01-24T21:56:00.370

Reputation: 4 989

2Congrats on exactly 1k rep! – ETHproductions – 2016-01-24T23:39:29.203

@ETHproductions thanks! I previously had 1.2k but then I gave a bounty for an answer in SPL :P – cat – 2016-01-24T23:46:28.740

1

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!");
}

cat

Posted 2016-01-24T21:56:00.370

Reputation: 4 989

1I count 35 bytes... – Addison Crump – 2016-01-24T23:03:15.717

@FlagAsSpam I can count today!! – cat – 2016-01-24T23:11:14.017

1

Pascal (FP/GP), 51 bytes

program h;begin writeln(StdErr,'Hello World!');end.

cat

Posted 2016-01-24T21:56:00.370

Reputation: 4 989

1

Perl, 25 24 bytes

say stderr"Hello World!"

Requires version 5.10 or later.

Thanks to @FlagAsSpam for a byte!

Doorknob

Posted 2016-01-24T21:56:00.370

Reputation: 68 138

Can you remove the space in stderr "Hello World!" (drop the comma). – Addison Crump – 2016-01-24T23:09:24.150

Well, I got ninja'd! – cat – 2016-01-24T23:09:55.187

@FlagAsSpam Nope. (This time for real.) – Doorknob – 2016-01-24T23:10:16.180

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. – Addison Crump – 2016-01-24T23:11:30.627

1Actually, you can remove the space (tested on perl 5.18.2). – Addison Crump – 2016-01-24T23:13:28.397

@FlagAsSpam ...huh. Apparently it didn't work in the debugger for some reason. Thanks! – Doorknob – 2016-01-24T23:14:13.770

This is valid in 5.20.2, too. – cat – 2016-01-24T23:20:48.433

Why not just die "Hello World!\n"? Try it online!

– Chris – 2019-10-04T21:32:35.803

1

Forth, 65 bytes

Shorter than factor!

outfile-id stderr to outfile-id ." Hello World!" cr to outfile-id

cat

Posted 2016-01-24T21:56:00.370

Reputation: 4 989

1

Moonscript, 40 bytes

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

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

cat

Posted 2016-01-24T21:56:00.370

Reputation: 4 989

1

Lua5.2, 41 bytes

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

Cheeky golfed version of the transpilation of my Moonscript answer.

cat

Posted 2016-01-24T21:56:00.370

Reputation: 4 989

0

Go, 39 38 37 70 69 bytes

package m;import."os";func main(){Stderr.WriteString("Hello World!")}

cat

Posted 2016-01-24T21:56:00.370

Reputation: 4 989

This is 37 bytes. – Addison Crump – 2016-01-24T22:29:04.893

@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. – cat – 2016-01-24T22:32:52.890

2Snippets are never a valid form of answer. Usually programs or functions are, but the question asks for a program. – feersum – 2016-01-24T22:33:59.823

@feersum you're right, but it's only mentioned offhandedly, not in the actual spec list. – cat – 2016-01-24T22:34:53.083

1Drop the comma. – Addison Crump – 2016-01-24T22:38:58.603

@FlagAsSpam thanks for that, I only changed that in the original post and not in the file I copied from :) – cat – 2016-01-24T22:39:56.437

0

Mathematica, 35 bytes

"stderr"~WriteString~"Hello World!"

Quite simple.

LegionMammal978

Posted 2016-01-24T21:56:00.370

Reputation: 15 731

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. – DavidC – 2016-01-25T00:08:30.003

@DavidC Run this as a script. – LegionMammal978 – 2016-01-25T00:53:10.473

I do not know what a script is. – DavidC – 2016-01-25T03:32:39.907

@DavidC Just put the code in a file, and run MathematicaScript -script <file>. – LegionMammal978 – 2016-01-25T11:41:04.373

0

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

echo Hello World! 1>&2

cat

Posted 2016-01-24T21:56:00.370

Reputation: 4 989

0

Perl 6, 19 21 bytes

note("Hello World!");

cat

Posted 2016-01-24T21:56:00.370

Reputation: 4 989

0

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*

cat

Posted 2016-01-24T21:56:00.370

Reputation: 4 989