Commit

39ec3a1

Writing to /dev/null in Multiple Programming Languages:
python
import os

with open('/dev/null', 'w') as f:
    f.write('This data will disappear.')
js
const fs = require('fs');

fs.writeFileSync('/dev/null', 'This data will disappear.');
go
package main

import "os"

func main() {
    f, _ := os.OpenFile(os.DevNull, os.O_WRONLY, 0)
    defer f.Close()
    f.WriteString("This data will disappear.")
}
rust
use std::fs::OpenOptions;
use std::io::Write;

fn main() -> std::io::Result<()> {
    let mut f = OpenOptions::new().write(true).open("/dev/null")?;
    f.write_all(b"This data will disappear.")?;
    Ok(())
}
c
#include <stdio.h>

int main(void) {
    FILE *f = fopen("/dev/null", "w");
    fputs("This data will disappear.", f);
    fclose(f);
    return 0;
}
cpp
#include <fstream>

int main() {
    std::ofstream f("/dev/null");
    f << "This data will disappear.";
    return 0;
}
java
import java.io.FileWriter;
import java.io.IOException;

public class Main {
    public static void main(String[] args) throws IOException {
        try (FileWriter f = new FileWriter("/dev/null")) {
            f.write("This data will disappear.");
        }
    }
}
kotlin
import java.io.File

fun main() {
    File("/dev/null").writeText("This data will disappear.")
}
csharp
using System.IO;

File.WriteAllText("/dev/null", "This data will disappear.");
php
<?php
file_put_contents('/dev/null', 'This data will disappear.');
ruby
File.open('/dev/null', 'w') do |f|
  f.write('This data will disappear.')
end
asm
section .data
    path    db "/dev/null", 0
    msg     db "This data will disappear."
    msg_len equ $ - msg

section .text
    global _start

_start:
    ; fd = open("/dev/null", O_WRONLY)
    mov rax, 2              ; sys_open
    lea rdi, [rel path]
    mov rsi, 1              ; O_WRONLY
    xor rdx, rdx
    syscall
    mov r12, rax            ; save the file descriptor

    ; write(fd, msg, msg_len)
    mov rax, 1              ; sys_write
    mov rdi, r12
    lea rsi, [rel msg]
    mov rdx, msg_len
    syscall

    ; close(fd)
    mov rax, 3              ; sys_close
    mov rdi, r12
    syscall

    ; exit(0)
    mov rax, 60             ; sys_exit
    xor rdi, rdi
    syscall

commit 39ec3a1