Skip to content

Commit 98ab768

Browse files
committed
stdout/stderr
1 parent 740e488 commit 98ab768

File tree

5 files changed

+96
-0
lines changed

5 files changed

+96
-0
lines changed

README.md

+74
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ This guide full of examples is intended for people learning Go that are coming f
126126
- [sha256](#crypto)
127127
- [env vars](#env-vars)
128128
- [cli args](#cli-args)
129+
- [stdout](#stdout)
130+
- [stderr](#stderr)
129131
- [stdin](#stdin)
130132
- [modules](#modules)
131133
- [stack trace](#stack-trace)
@@ -3103,6 +3105,78 @@ $ go run examples/cli_args.go foo bar qux
31033105
[foo bar qux]
31043106
```
31053107
3108+
### stdout
3109+
---
3110+
3111+
#### Node.js
3112+
3113+
```node
3114+
process.stdout.write('hello world\n')
3115+
```
3116+
3117+
Output
3118+
3119+
```bash
3120+
hello world
3121+
```
3122+
3123+
#### Go
3124+
3125+
```go
3126+
package main
3127+
3128+
import (
3129+
"fmt"
3130+
"os"
3131+
)
3132+
3133+
func main() {
3134+
fmt.Fprint(os.Stdout, "hello world\n")
3135+
}
3136+
```
3137+
3138+
Output
3139+
3140+
```bash
3141+
hello world
3142+
```
3143+
3144+
### stderr
3145+
---
3146+
3147+
#### Node.js
3148+
3149+
```node
3150+
process.stderr.write('hello error\n')
3151+
```
3152+
3153+
Output
3154+
3155+
```bash
3156+
hello error
3157+
```
3158+
3159+
#### Go
3160+
3161+
```go
3162+
package main
3163+
3164+
import (
3165+
"fmt"
3166+
"os"
3167+
)
3168+
3169+
func main() {
3170+
fmt.Fprint(os.Stdout, "hello error\n")
3171+
}
3172+
```
3173+
3174+
Output
3175+
3176+
```bash
3177+
hello error
3178+
```
3179+
31063180
### stdin
31073181
---
31083182

examples/stderr.go

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
)
7+
8+
func main() {
9+
fmt.Fprint(os.Stdout, "hello error\n")
10+
}

examples/stderr.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
process.stderr.write('hello error\n')

examples/stdout.go

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
)
7+
8+
func main() {
9+
fmt.Fprint(os.Stdout, "hello world\n")
10+
}

examples/stdout.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
process.stdout.write('hello world\n')

0 commit comments

Comments
 (0)