Stdin/Stdout woes

1,666 views
Skip to first unread message

Steven Degutis

unread,
Aug 21, 2012, 8:02:35 PM8/21/12
to golan...@googlegroups.com
I've been trying to write a very simple program today that is like cat but makes everything uppercase.

Technically it works as expected at the command line. But I'm running it via an NSTask within an OS X app, and it's giving me exit status code 11 with nothing printed to stdout or stderr. I know it's not a problem with NSTask because using it with the actual `cat` command works just fine (exit code 0, prints everything from stdin to stdout).

Can anyone spot a flaw in this Go program that would cause such an issue to arise? Here's what I have:

package main

import "os"
import "strings"
import "io"
import "io/ioutil"

func main() {
  b, _ := ioutil.ReadAll(os.Stdin)
  s := strings.ToUpper(string(b))
  io.WriteString(os.Stdout, s)
  //os.Stdout.Sync()
  //os.Stdout.Close()
}

As you can see I've also experimented with trying to manually flush and close Stdout, to no avail.

Any ideas?

-Steven

Rob Pike

unread,
Aug 21, 2012, 8:10:43 PM8/21/12
to Steven Degutis, golan...@googlegroups.com
Where are stdin and stdout directed in that environment? First guess
is they're pointed at /dev/null or some file.

-rob

Kyle Lemons

unread,
Aug 21, 2012, 8:25:23 PM8/21/12
to Steven Degutis, golan...@googlegroups.com
Have you tried running Hello, World?  If that works, it might mean it's an issue with i/o.  If it doesn't, the problem might lie elsewhere.

Steven Degutis

unread,
Aug 21, 2012, 8:50:10 PM8/21/12
to golan...@googlegroups.com, Steven Degutis
Thanks Rob and Kyle, it's definitely a problem on the OS X side. Originally forgot to verify it with the basic `fmt.Println("hello world")` but that definitely suggests it's not something I need to change in the Go program to get it working. Which makes sense because OS X is insane.

-Steven

minux

unread,
Aug 22, 2012, 2:32:08 AM8/22/12
to Steven Degutis, golan...@googlegroups.com
On Wed, Aug 22, 2012 at 8:50 AM, Steven Degutis <sdeg...@8thlight.com> wrote:
Thanks Rob and Kyle, it's definitely a problem on the OS X side. Originally forgot to verify it with the basic `fmt.Println("hello world")` but that definitely suggests it's not something I need to change in the Go program to get it working. Which makes sense because OS X is insane.
have you tried to add a dummy "C" import to the Go program to see if it works?
as explained in reply to your other post, it could fix the problem if has something to
do with dynamic linking.

Steve McCoy

unread,
Aug 22, 2012, 11:37:08 AM8/22/12
to golan...@googlegroups.com
Use spotlight to open up "Console", one of the logs in there is where std* go when there's no terminal/file assigned to a process, which is the usual case for apps.
Reply all
Reply to author
Forward
0 new messages