Skip to content

Instantly share code, notes, and snippets.

@Likk
Last active July 3, 2019 02:08
Show Gist options
  • Save Likk/92c84643491849b5d210c931a1d84a80 to your computer and use it in GitHub Desktop.
Save Likk/92c84643491849b5d210c931a1d84a80 to your computer and use it in GitHub Desktop.
GoのバイナリをPerl/Ruby/PHPスクリプトとしても扱う (元ネタ https://codehex.hateblo.jp/entry/2019/07/02/090000 https://uzulla.hateblo.jp/entry/2019/07/02/191859)
package main
import (
"fmt"
"io/ioutil"
)
const script = `<?php
file_put_contents("php://stderr", "This is PHP world!!!".PHP_EOL);
__halt_compiler();
#!perl
#!ruby
$Ruby="perl";
print "Hello, $Ruby World!!\n";
__END__
`
func init() {
ioutil.Discard.Write([]byte(script))
}
func main() {
fmt.Println("This is Go world!!")
}
@Likk
Copy link
Author

Likk commented Jul 2, 2019

$ go build -o main ./main.go;
$ ./main && ( perl -x ./main )&& ( ruby -x ./main) && (php ./main 2>&1 > /dev/null)

This is Go world!!
Hello, perl World!!
Hello, $Ruby World!!
This is PHP world!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment