GoLang-termbox:紧急情况:打开/dev/tty:没有此类设备或地址 [英] GoLang - termbox: panic: open /dev/tty: no such device or address

查看:135
本文介绍了GoLang-termbox:紧急情况:打开/dev/tty:没有此类设备或地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Ubuntu 12.04 LTS机器上使用Go 1.2进行编码-使用LiteIDE(对此非常满意).

我下载并安装了 go termbox软件包 -构建了演示键盘.go-建造良好.

但是当我从LiteIDE运行时,我会感到恐慌-所有termbox演示都发生同样的事情:

panic: open /dev/tty: no such device or address

任何线索都会有所帮助....

解决方案

好吧,这是完全合理的: interactive 终端应用程序要求 terminal 可用.终端可以是真实的硬件—或虚拟的(例如您在典型的x86上看到的Linux虚拟终端)当您按下Ctrl-Alt-F1组合键或模拟时(如xterm,rxvt,GNOME Terminal和大量其他工具所提供的).

与Windows相反,在Windows中,运行控制台"类型的程序会强制创建控制台窗口并附加一个应用程序,而在POSIX系统上则没有类型"的应用程序,并且如果应用程序需要一个真正的终端对其I/O可用时,它会对此进行特殊检查,如果失败,则应用程序会发出错误信号并退出 1 .如今,很少有人能够使用真正的硬件终端,因此大部分时间都在使用仿真,然后我们讨论所谓的go termbox package - built the demo keyboard.go - built fine.

But when I run from LiteIDE, I get this panic - same happens with all the termbox demos:

panic: open /dev/tty: no such device or address

Any clues would be helpful....

解决方案

OK, that's completely reasonable: interactive terminal applications require, well, terminal to be available. Terminals may be real—hardware—or virtual (like Linux virtual terminals you see on a typical x86 box when you hit Ctrl-Alt-F1) or emulated (like those provided by xterm, rxvt, GNOME Terminal and a ton of others).

Contrary to Windows, in which running a program of type "console" forces a console window to be created and an application attached to it, on POSIX systems there's no "types" of applications, and if an aplication wants a real terminal available for its I/O it performs a special check for this, and if that fails, the application signals an error and quits1. Very few folks have access to real hardware terminals these days so most of the time emulation is used, and then we talk about the so-called pseudo terminals. Linux virtual terminals and GUI terminal emulators and terminal console multiplexors like screen and tmux—all of them allocate pseudo terminals for running programs they control.

So basically you have these options:

  • Find a setting in your IDE which makes it allocate a pseudo-terminal when running your program. Some programs are able to do that by embedding a terminal emulator into their UI or by running it explicitly.

  • Teach your IDE to run your program in a terminal emulator. Most of them obey the convention established by the venerable xterm and accept the -e <program> command-line option, so instead of

    ./myprogram
    

    your IDE should run

    xterm -e ./myprogram
    

    If you're on a Debian system or its derivative, you might get away with

    x-terminal-emulator -e ./myprogram
    

    which is supposed to spawn your preferred terminal emulator program.

  • Stop running the code in the IDE and do it in a terminal emulator using the regular

    go build
    ./myprogram
    

    workflow.

I've never used LiteIDE so have no immediate experience with how to do that in it—you'll have to do your own research.


1 Some programs may happily work with or without being attached to a terminal, with shells (like bash or zsh) and interpreters (like Tcl or Python) being good examples: when they detect a terminal device available, they go into interactive mode, enable line editing and so on, otherwise they just read the code from their standard input and execute it. Another good example is Git: its high-level programs detect if they're attached to a terminal and if so they might enable colouring of their output and automatically spawn a pager program if their output if about to overflow the single screenful of lines; otherwise they cut the fuss and just dump their output to their standard output stream.

这篇关于GoLang-termbox:紧急情况:打开/dev/tty:没有此类设备或地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆