duanqian2368 2014-02-18 06:25
浏览 282
已采纳

GoLang-termbox:紧急情况:打开/ dev / tty:没有此类设备或地址

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条回答 默认 最新

  • douliaodun9153 2014-02-18 15:54
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 vue3加ant-design-vue无法渲染出页面
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序