GoLang – termbox: panic: 打开 /dev/tty: 没有这样的设备或地址

huangapple go评论98阅读模式
英文:

GoLang - termbox: panic: open /dev/tty: no such device or address

问题

我正在使用LiteIDE在Ubuntu 12.04 LTS机器上编写Go 1.2代码(非常满意)。

我下载并安装了go termbox包,并构建了演示程序keyboard.go,构建成功。

但是当我从LiteIDE运行时,出现了以下panic错误,所有termbox演示程序都会出现相同的问题:

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

希望能提供一些线索。

英文:

I am coding with Go 1.2 on Ubuntu 12.04 LTS machine - using LiteIDE (very pleased with it).

I downloaded and installed the 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....

答案1

得分: 6

好的,以下是翻译好的内容:

好的,这完全合理:交互式终端应用程序需要终端可用。终端可以是真实的-硬件终端(如硬件终端),也可以是虚拟的(例如在典型的x86计算机上按下<键>Ctrl-Alt-F1时看到的Linux虚拟终端)或模拟的(例如由xterm、rxvt、GNOME终端等提供的终端)。与Windows相反,在Windows中,运行“控制台”类型的程序会强制创建一个控制台窗口,并将应用程序附加到该窗口上,而在POSIX系统中,没有“类型”应用程序的概念,如果应用程序需要一个真实的终端用于其输入/输出,它会执行一个特殊的检查,如果检查失败,应用程序会发出错误信号并退出<sup>1</sup>。如今,很少有人可以访问真实的硬件终端,所以大多数情况下使用模拟终端,这就是所谓的伪终端。Linux虚拟终端、GUI终端模拟器和终端控制台复用器(如screentmux)-它们都为它们控制的运行程序分配伪终端。

所以基本上你有以下几个选择:

  • 在你的IDE中找到一个设置,使其在运行程序时分配一个伪终端。一些程序可以通过将终端模拟器嵌入到其用户界面中或显式运行终端模拟器来实现这一点。

  • 教会你的IDE在终端模拟器中运行你的程序。大多数IDE遵循由古老的xterm建立的约定,并接受-e &lt;program&gt;命令行选项,所以你的IDE应该运行

      xterm -e ./myprogram
    

    如果你使用的是Debian系统或其衍生系统,你可以尝试

      x-terminal-emulator -e ./myprogram
    

    这应该会启动你首选的终端模拟器程序。

  • 停止在IDE中运行代码,改用终端模拟器使用常规的

      go build
      ./myprogram
    

    工作流程。

我从未使用过LiteIDE,所以对如何在其中执行这些操作没有直接经验-你需要自己进行研究。


<sup>1</sup> 有些程序可以在有或没有终端附加的情况下正常工作,其中shell(如bashzsh)和解释器(如TclPython)是很好的例子:当它们检测到可用的终端设备时,它们进入交互模式,启用行编辑等等,否则它们只是从标准输入读取代码并执行。另一个很好的例子是Git:它的高级程序会检测它们是否附加到终端,如果是,则可能启用其输出的着色,并在输出即将溢出单个屏幕行数时自动生成一个分页程序;否则,它们只是将其输出转储到标准输出流中。

英文:

OK, that's completely reasonable: interactive terminal applications require, well, terminal to be available. Terminals may be real&mdash;hardware&mdash;or virtual (like Linux virtual terminals you see on a typical x86 box when you hit <key>Ctrl-Alt-F1</key>) 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 quits<sup>1</sup>. 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&mdash;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 &lt;program&gt; 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&mdash;you'll have to do your own research.


<sup>1</sup> 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.

huangapple
  • 本文由 发表于 2014年2月18日 14:25:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/21845871.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定