发布时grunt shell:test,我收到警告"输入设备不是TTY"并且不想使用-f:
$ grunt shell:test
Running "shell:test" (shell) task
the input device is not a TTY
Warning: Command failed: /bin/sh -c ./run.sh npm test
the input device is not a TTY
Use --force to continue.
Aborted due to warnings.
Run Code Online (Sandbox Code Playgroud)
这是Gruntfile.js命令:
shell: {
test: {
command: './run.sh npm test'
}
Run Code Online (Sandbox Code Playgroud)
这是run.sh:
#!/bin/sh
# should use the latest available image to validate, but not LATEST
if [ -f .env ]; then
RUN_ENV_FILE='--env-file .env'
fi …Run Code Online (Sandbox Code Playgroud) 我想在Linux系统上用C编写一个简单,愚蠢的X终端模拟器.
起初,我只是想我必须打开一个shell并显示它的输出.我检查了xterm和rxvt代码,看起来有点复杂.
首先,我必须用openpty打开一个伪终端.所以我看一下手册页,看看openpty填充了2个文件描述符,即master和slave.xterm和rxvt代码都很混乱,因为这些特殊文件的系统依赖性.
我理解termios的东西:它只是关于终端转义码的一堆信息.我真正没有得到的是:我想对主/从文件描述符做什么?
打开终端,登录,在shell上执行"ls"的示例程序将是非常棒的.
(英语不是我的母语,原谅我最终的错误)
编辑:这是我提出的示例代码:
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <pty.h>
#include <utmp.h>
#include <ctype.h>
void
safe_print (char* s)
{
while(*s) {
if(*s == '\n')
putchar("\n");
else if(iscntrl(*s))
printf("\\e(%d)", *s);
else
putchar(*s);
s++;
}
}
int
main (int argc, char** argv)
{
char buf[BUFSIZ] = {0};
int master;
int ret = forkpty(&master, NULL, NULL, NULL);
if(ret == -1)
puts("no fork"), exit(0);
if(!ret) {
execl("/bin/sh", "sh", NULL);
exit(0);
}
sleep(1); /* let the shell run …Run Code Online (Sandbox Code Playgroud) 我想读的,一时间从PHP命令行中的一个字符,但它好像有某种输入缓冲从某处防止这种.
考虑以下代码:
#!/usr/bin/php
<?php
echo "input# ";
while ($c = fread(STDIN, 1)) {
echo "Read from STDIN: " . $c . "\ninput# ";
}
?>
Run Code Online (Sandbox Code Playgroud)
键入"foo"作为输入(并按Enter键),我得到的输出是:
input# foo
Read from STDIN: f
input# Read from STDIN: o
input# Read from STDIN: o
input# Read from STDIN:
input#
Run Code Online (Sandbox Code Playgroud)
我期待的输出是:
input# f
input# Read from STDIN: f
input# o
input# Read from STDIN: o
input# o
input# Read from STDIN: o
input#
input# Read from STDIN:
input#
Run Code Online (Sandbox Code Playgroud)
(即,在键入字符时读取和处理字符).
但是,目前,只有在按下输入后才会读取每个字符.我怀疑TTY正在缓冲输入.
最终我希望能够读取按下箭头,向下箭头等按键.
我正在寻找STDIN从外部进程向现有进程写入数据的方法,并发现了类似的问题 如何将数据从Python中的不同本地/远程进程流式传输到程序的STDIN中?在stackoverlow中.
在那个帖子中,@ Michael说我们可以在下面的路径中获取现有进程的文件描述符,并允许在Linux上将数据写入其中.
/proc/$PID/fd/
Run Code Online (Sandbox Code Playgroud)
所以,我创建了一个下面列出的简单脚本来测试从外部进程向脚本STDIN(和TTY)写入数据.
#!/usr/bin/env python
import os, sys
def get_ttyname():
for f in sys.stdin, sys.stdout, sys.stderr:
if f.isatty():
return os.ttyname(f.fileno())
return None
if __name__ == "__main__":
print("Try commands below")
print("$ echo 'foobar' > {0}".format(get_ttyname()))
print("$ echo 'foobar' > /proc/{0}/fd/0".format(os.getpid()))
print("read :: [" + sys.stdin.readline() + "]")
Run Code Online (Sandbox Code Playgroud)
这个测试脚本显示的路径STDIN和TTY,然后,等待一个写它STDIN.
我启动了这个脚本并在下面收到了消息.
Try commands below
$ echo 'foobar' > /dev/pts/6
$ echo 'foobar' > /proc/3308/fd/0
Run Code Online (Sandbox Code Playgroud)
所以,我执行的命令echo 'foobar' …
如何用Go lang获得tty尺寸?我正在尝试执行stty size命令,但我无法正确编写代码.
package main
import (
"os/exec"
"fmt"
"log"
)
func main() {
out, err := exec.Command("stty", "size").Output()
fmt.Printf("out: %#v\n", out)
fmt.Printf("err: %#v\n", err)
if err != nil {
log.Fatal(err)
}
}
Run Code Online (Sandbox Code Playgroud)
输出:
out: []byte{}
err: &exec.ExitError{ProcessState:(*os.ProcessState)(0xc200066520)}
2013/05/16 02:35:57 exit status 1
exit status 1
Run Code Online (Sandbox Code Playgroud)
我认为这是因为Go产生了一个与当前tty无关的进程,它正在使用它.如何将命令与当前终端关联以获得其大小?
我正在使用屏幕从串行控制台读取文本.问题是输出似乎只有换行符\n而不是回车符\ r \n,所以显示看起来像这样......
Line1
Line2
Line3
Run Code Online (Sandbox Code Playgroud)
我想知道是否有任何补丁来解决这个问题?
每当我使用grep,并将其管道到其他程序时,该--color选项不受尊重.我知道我可以使用--color=always,但它也提出了一些其他命令,我想得到该命令的确切输出,如果我在tty中我将得到的输出.
所以我的问题是,是否有可能欺骗命令认为命令是在tty内运行的?
例如,跑步
grep --color word file # Outputs some colors
grep --color word file | cat # Doesn't output any colors
Run Code Online (Sandbox Code Playgroud)
我希望能够写出类似的东西:
IS_TTY=TRUE grep --color word file | cat # Outputs some colors
Run Code Online (Sandbox Code Playgroud)
这个问题似乎有一个工具,可能会做我想要的:空 - 在伪终端(PTY)下运行进程和应用程序,但从我在文档中读到的,我不确定它可以帮助我的问题
我想写一个简单的C程序,它将根据"key down"和"key up"事件执行不同的操作.该程序将从rxvt内部运行.
我应该使用什么库或机制来访问按键和释放?阅读/dev/tty只会提供关键版本吗?对于termcap,terminfo,ncurses和俚语,这也是如此吗?有没有办法在终端应用程序中实现这一目标?
我在Linux中有一个程序,如果它的stdin/stdout不是TTY(终端设备),它就拒绝运行.是否有一个易于使用的工具,它将创建一个PTY,使用新创建的TTY启动程序,并通过stdin/stdout复制所有数据?
用例不是交互式的,而是脚本的.我正在寻找最轻量级的解决方案,最好不要创建TCP连接,也不需要安装太多其他工具和库.
问题:vagrant up失败,错误如下.我在Windows 7上运行vagrant,基本框是Ubuntu)(files.vagrantup.com/precise32.box).
怎么修好?
vagrant.bat up
Bringing machine 'default' up with 'virtualbox' provider...
[default] Clearing any previously set forwarded ports...
[default] Clearing any previously set network interfaces...
[default] Available bridged network interfaces:
1) Intel(R) PRO/1000 EB Network Connection with I/O Acceleration
2) Intel(R) PRO/1000 PL Network Connection
Vagrant is attempting to interface with the UI in a way that requires
a TTY. Most actions in Vagrant that require a TTY have configuration
switches to disable this requirement. Please do that …Run Code Online (Sandbox Code Playgroud)