Last active
July 3, 2019 02:08
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!!") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$ go build -o main ./main.go;
$ ./main && ( perl -x ./main )&& ( ruby -x ./main) && (php ./main 2>&1 > /dev/null)