标签: tty

Linux:我可以在不使用任何IPC(管道等)的情况下读取另一个进程的输出吗?

是否有可能在linux中以某种方式读取另一个进程的输出(来自stdout和stderr)而不知道它?所以假设我有一个进程A在后台运行而进程B想要读取它的输出 - 这可能吗?我不能使用管道或屏幕程序.我尝试从/ proc/xxx/fd或/ pts/x控制台等读取,但到目前为止没有任何工作.

linux process tty

6
推荐指数
1
解决办法
550
查看次数

在 tty 之间移动作业

有人知道是否可以在 tty 之间转移工作吗?

示例:在 ttys004 启动作业,按 Ctrl+Z 将其分离,输入 bg 1 将其移至后台。然后我想从示例 ttys002 到达它。

linux background tty

6
推荐指数
1
解决办法
1827
查看次数

什么是 TTY,如何在 Ubuntu 上启用它?

我目前正在设置一个 node.js 服务器,我正在使用这里的调试模块https://github.com/visionmedia/debug

我正在尝试启用它,以便我可以在输出中获取彩色调试信息,但是我的终端看起来像底部的最后一个终端屏幕,它说:

When stdout is not a TTY, Date#toUTCString() is used, making it more useful for logging the debug information as shown below:
Run Code Online (Sandbox Code Playgroud)

任何人都可以对此有所了解吗?谢谢。

ubuntu stdout tty node.js

6
推荐指数
1
解决办法
4145
查看次数

从bash脚本中愚弄python的os.isatty

我正在编写一个将从cron调用的bash脚本.

bash脚本运行一个python命令,通过使用pythons os.isatty函数检测它何时在终端中, 并输出不同的东西,具体取决于它是手动运行还是通过cron运行.这使得调试非常困难,我想这样做,以便它总是假设它不在TTY中.

我希望能够在bash脚本中添加一些内容来欺骗它不在终端中运行的python脚本,因此总是输出相同的东西.

为了确认,我控制了bash脚本,但不想编辑python,因为这是一个打包的应用程序.

有任何想法吗?

我希望这是有道理的.

非常感谢你提前.

python bash cron tty

6
推荐指数
1
解决办法
1830
查看次数

为什么 terminfo[kcuu1] = '\EOA'?

据我所知terminfo(5),kcuu1 应该是按下向上箭头时终端发送的序列。我从来没有见过除了^[[A(现在谈论cat,搞乱终端设置等)以外的任何东西。那么,鉴于我使用的终端(rxvt、gnome-terminal、iTerm)都默认为 TERM=xterm,为什么不是 kcuu1 \E[A

我看到 cuu1 \E[A,但是(再次从手册页),这是我应该发送到终端以移动光标的字符串,而不是终端发送给我的字符串。

顺便说一句,这是 OS X 的情况。

tty termcap terminfo

6
推荐指数
1
解决办法
1458
查看次数

在node.js中使用tty生成子进程

我正在尝试使用ssh在远程服务器上做一些工作 - 并且从node.js在本地机器上调用ssh

脚本的精简版本如下所示:

var execSync = require("child_process").execSync;
var command =
  'ssh -qt user@remote.machine -- "sudo mv ./this.thing /to/here/;"';
execSync(command,callback);

function callback(error,stdout,stderr) {

  if (error) {
    console.log(stderr);
    throw new Error(error,error.stack);
  }
  console.log(stdout);
}
Run Code Online (Sandbox Code Playgroud)

我收到了requiretty错误sudo: sorry, you must have a tty to run sudo.

如果我ssh -qt user@remote.machine -- "sudo mv ./this.thing /to/here/;"直接从命令行运行 - 换句话说,直接从tty运行 - 我没有错误,并且this.thing移动/to/there/得很好.

这是部署脚本的一部分,它真的不适合添加!requiretty到sudoers文件.

反正有没有让node.js在tty中运行命令?

javascript ssh tty child-process node.js

6
推荐指数
1
解决办法
4882
查看次数

Gradle - 如何在tty中运行exec?

几天后我对Gradle有一点问题.当我从tty运行Gradle build时(例如在带有oh-my-zsh的iTerm中),我调用了其他一些控制台命令,我期待所有被调用的进程也将在这个tty中运行...但他们不是!这个过程的输出甚至没有颜色......调用:

exec {
    commandLine "tty"
}
Run Code Online (Sandbox Code Playgroud)

产生的输出如:"不是tty".有谁想,如何解决这个问题?

exec tty gradle

6
推荐指数
0
解决办法
308
查看次数

在 Rust 中,如何用颜色捕获过程输出?

我想捕获另一个进程的输出(例如git status),对其进行处理,并使用所有样式(粗体、斜体、下划线)和颜色进行打印。进一步处理它对我来说非常重要String,我不想只打印它。

在 Unix 世界中,我认为这会涉及转义码,我不确定 Windows 世界,但这对我也很重要。

我知道如何在没有颜色的情况下做到这一点:

fn exec_git() -> String {
    let output = Command::new("git")
        .arg("status")
        .output()
        .expect("failed to execute process");

    String::from_utf8_lossy(&output.stdout).into_owned()
}
Run Code Online (Sandbox Code Playgroud)

也许我应该改用spawn

terminal console tty windows-console rust

6
推荐指数
1
解决办法
4500
查看次数

微小的tty linux设备驱动程序的奇怪行为

我在Linux设备驱动程序一书中找到的这个小小的驱动程序遇到了麻烦.我必须略微采用代码以满足我的要求,因此踢掉了任何不相关的代码(参见下面的代码).

我使用一个内核线程将"hello world"写入TTY层.如果我使用cat命令在终端中打开设备文件,我会收到预期的字符串.

但我面临两个问题:

  1. 为什么在我的内核线程(tiny_thread)中调用tty_insert_flip_char(...)时会调用tiny_write(...)?只有在写入设备文件时才应该调用tiny_write(...)函数吗?如果在读取或写入操作期间调用它,如何区分此函数?
  2. 如果在设备文件上使用echo,为什么会出现错误?

    echo test > /dev/tiny_tty
    bash: echo: write error: Invalid argument
    
    Run Code Online (Sandbox Code Playgroud)

驱动程序在Raspberry Pi内核4.9.56-v7上运行.

非常感谢!

此致,托马斯

更新:使用tty_flip_buffer_push()中的解决方案(部分)解决了第一个问题,将数据发送回自身.有没有办法直接在设备驱动程序中执行此操作,因此用户不需要进行任何交互?

/*
 * Tiny TTY driver
 *
 * Base on tiny tty driver from Greg Kroah-Hartman
 */

#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/wait.h>
#include <linux/tty.h>
#include <linux/tty_driver.h>
#include <linux/tty_flip.h>
#include <linux/serial.h>
#include <linux/sched.h>
#include <linux/seq_file.h>
#include <asm/uaccess.h>
#include <linux/kthread.h>
#include <linux/jiffies.h>

#define USE_SIMULATOR

#define DELAY_TIME      HZ * 2  /* …
Run Code Online (Sandbox Code Playgroud)

linux tty linux-device-driver

6
推荐指数
1
解决办法
334
查看次数

Docker ubuntu cron 尾部日志不可见

尝试运行具有 cron 调度的 docker 容器。但是我不能让它输出日志。

我正在使用 docker-compose。

docker-compose.yml

---
version: '3'
services:
  cron:
    build:
      context: cron/
    container_name: ubuntu-cron
Run Code Online (Sandbox Code Playgroud)

定时/Dockerfile

FROM ubuntu:18.10

RUN apt-get update
RUN apt-get update && apt-get install -y cron 

ADD hello-cron /etc/cron.d/hello-cron

# Give execution rights on the cron job
RUN chmod 0644 /etc/cron.d/hello-cron

# Create the log file to be able to run tail
RUN touch /var/log/cron.log

# Run the command on container startup
CMD cron && tail -F /var/log/cron.log
Run Code Online (Sandbox Code Playgroud)

cron/你好-cron

* * * * * …
Run Code Online (Sandbox Code Playgroud)

cron logging tty docker docker-compose

6
推荐指数
2
解决办法
3067
查看次数