// -*- java -*- // smallest // the smallest running program doing nothing class smallest { static void Main() { } } // hello world // print a simple string on stdout class hello_world { static void Main() { System.Console.WriteLine("Hello World"); } } // argv // access command line parameters (no segmentation fault accepted, nor silent exception, so some languages must explicitly check the presence of the argument) class argv { static void Main(string[] args) { if (args.Length > 0) System.Console.WriteLine(args[0]); } } // env // access environment variable using System; class env { static void Main() { Console.WriteLine(Environment.GetEnvironmentVariable("HOME")); } } // test file exists // return exit code error (non zero) if a file does not exist public class exists { static int Main() { return (new System.IO.FileInfo("/etc/mtab")).Exists ? 0 : 1; } } // test file readable // return exit code error (non zero) if a file is not readable public class readable { static int Main() { try { (new System.IO.FileInfo("/etc/mtab")).OpenRead(); return 0; } catch(System.Exception ex) { return 1; } } } // formatting // print integers in a simple formatted string class formatting { static void Main() { int a=1, b=2; System.Console.WriteLine("{0} + {1} = {2}", a, b, a + b); } } // system // call an external program and check the return value using System; using System.Diagnostics; public class system { static void Main() { Process proc = new Process(); proc.EnableRaisingEvents = false; proc.StartInfo.FileName = "false"; proc.Start(); proc.WaitForExit(); if (proc.ExitCode != 0) Console.Error.WriteLine("false failed"); proc.StartInfo.FileName = "echo"; proc.StartInfo.Arguments = "done"; proc.Start(); proc.WaitForExit(); } }