Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
miniliuke
V2EX  ›  Linux

怎么让后台程序输入输出到指定终端

  •  
  •   miniliuke · Sep 7, 2018 · 2844 views
    This topic created in 2813 days ago, the information mentioned may be changed or developed.

    开了两个终端 pts/0 和 pts/1 现在有个后台程序(或者运行在 pts/1 上)希望将输出输出至 pts/0,并且从 pts/0 里读输入......怎么做?pts/0 的文件为 /dev/pts/0,我运行 echo "hello">/dev/pts/0,的确 pts/0 收到了 hello,但是我试着用 Golang 打开文件 os.Open("/dev/pts/0")然后写文件,确没有起作用,到底该怎么办呢

    
    cmd := exec.Command("ps","a")
    cmd.Stdin = file
    cmd.Stdout = file // file 就是 /dev/pts/0
    cmd.Stderr = os.Stderr
    cmd.Run()
    

    也没作用

    1 replies    2018-09-07 14:51:21 +08:00
    miniliuke
        1
    miniliuke  
    OP
       Sep 7, 2018
    发现是 os.Open 的锅,使用 os.Openfile 能输出了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1158 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 17:55 · PVG 01:55 · LAX 10:55 · JFK 13:55
    ♥ Do have faith in what you're doing.