是否有可能在linux中以某种方式读取另一个进程的输出(来自stdout和stderr)而不知道它?所以假设我有一个进程A在后台运行而进程B想要读取它的输出 - 这可能吗?我不能使用管道或屏幕程序.我尝试从/ proc/xxx/fd或/ pts/x控制台等读取,但到目前为止没有任何工作.
有人知道是否可以在 tty 之间转移工作吗?
示例:在 ttys004 启动作业,按 Ctrl+Z 将其分离,输入 bg 1 将其移至后台。然后我想从示例 ttys002 到达它。
我目前正在设置一个 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)
任何人都可以对此有所了解吗?谢谢。
我正在编写一个将从cron调用的bash脚本.
bash脚本运行一个python命令,通过使用pythons os.isatty函数检测它何时在终端中, 并输出不同的东西,具体取决于它是手动运行还是通过cron运行.这使得调试非常困难,我想这样做,以便它总是假设它不在TTY中.
我希望能够在bash脚本中添加一些内容来欺骗它不在终端中运行的python脚本,因此总是输出相同的东西.
为了确认,我控制了bash脚本,但不想编辑python,因为这是一个打包的应用程序.
有任何想法吗?
我希望这是有道理的.
非常感谢你提前.
据我所知terminfo(5),kcuu1 应该是按下向上箭头时终端发送的序列。我从来没有见过除了^[[A(现在谈论cat,搞乱终端设置等)以外的任何东西。那么,鉴于我使用的终端(rxvt、gnome-terminal、iTerm)都默认为 TERM=xterm,为什么不是 kcuu1 \E[A?
我看到 cuu1是 \E[A,但是(再次从手册页),这是我应该发送到终端以移动光标的字符串,而不是终端发送给我的字符串。
顺便说一句,这是 OS X 的情况。
我正在尝试使用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中运行命令?
几天后我对Gradle有一点问题.当我从tty运行Gradle build时(例如在带有oh-my-zsh的iTerm中),我调用了其他一些控制台命令,我期待所有被调用的进程也将在这个tty中运行...但他们不是!这个过程的输出甚至没有颜色......调用:
exec {
commandLine "tty"
}
Run Code Online (Sandbox Code Playgroud)
产生的输出如:"不是tty".有谁想,如何解决这个问题?
我想捕获另一个进程的输出(例如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?
我在Linux设备驱动程序一书中找到的这个小小的驱动程序遇到了麻烦.我必须略微采用代码以满足我的要求,因此踢掉了任何不相关的代码(参见下面的代码).
我使用一个内核线程将"hello world"写入TTY层.如果我使用cat命令在终端中打开设备文件,我会收到预期的字符串.
但我面临两个问题:
如果在设备文件上使用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) 尝试运行具有 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)