我写了一个PHP脚本.我希望它在使用连接到tty设备(终端)的标准输入调用之前显示帮助消息,然后以交互方式进行读取和执行,但是在使用文件或来自管道的流作为标准输入调用时不显示.
有没有办法从PHP中检测到这个?
我试图附加到Kubernetes中的正在运行的容器,但是我收到下面的错误消息.
>kubectl attach -it es-client-2756725635-4rk43 -c es-node
Unable to use a TTY - container es-node did not allocate one
If you don't see a command prompt, try pressing enter.
Run Code Online (Sandbox Code Playgroud)
如何在容器yaml中启用TTY?
我需要在Python中使用它自己的专用TTY在一个单独的进程中运行一个交互式Bash实例(我不能使用pexpect).我使用了这个通常在类似程序中使用过的代码片段:
master, slave = pty.openpty()
p = subprocess.Popen(["/bin/bash", "-i"], stdin=slave, stdout=slave, stderr=slave)
os.close(slave)
x = os.read(master, 1026)
print x
subprocess.Popen.kill(p)
os.close(master)
Run Code Online (Sandbox Code Playgroud)
但是当我运行它时,我得到以下输出:
$ ./pty_try.py
bash: cannot set terminal process group (10790): Inappropriate ioctl for device
bash: no job control in this shell
Run Code Online (Sandbox Code Playgroud)
运行的Strace显示一些错误:
...
readlink("/usr/bin/python2.7", 0x7ffc8db02510, 4096) = -1 EINVAL (Invalid argument)
...
ioctl(3, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, 0x7ffc8db03590) = -1 ENOTTY (Inappropriate ioctl for device)
...
readlink("./pty_try.py", 0x7ffc8db00610, 4096) = -1 EINVAL (Invalid argument)
Run Code Online (Sandbox Code Playgroud)
代码片段看起来很简单,Bash没有得到它需要的东西吗?这可能是什么问题?
我需要将命令从一个终端写入另一个终端.
我试过这些:
echo -e "ls\n" > /proc/pid/fd/0
echo -e "ls\n" > /dev/pts/4
Run Code Online (Sandbox Code Playgroud)
它只打印ls输出而不执行.
我试过这些:
chmod 777 /dev/tty4 ;echo "ls" > /dev/tty4
chmod 777 /dev/tty40 ;echo "ls" > /dev/tty40
Run Code Online (Sandbox Code Playgroud)
哪个似乎什么也没做
有任何想法吗?
[请注意,我不想触摸第二个终端来完成此任务.只有第一个]
我是汇编的初学者(使用nasm).我正在通过大学课程学习集会.
我试图了解sys_read linux系统调用时的行为.具体来说,sys_read在读取新行或换行符时停止.根据我所教的,这是事实.这篇在线教程文章也肯定了事实/主张.
当sys_read检测到换行时,控制返回到程序,用户输入位于您在ECX中传递的内存地址.
我检查了linux程序员的sys_read调用手册(通过"man 2 read").它没有提到它应该的行为,对吧?
read()尝试从buf开始读取从文件描述符fd到缓冲区的字节数.
在支持搜索的文件上,读取操作从文件偏移开始,文件偏移量增加读取的字节数.如果文件偏移量等于或超过文件末尾,则不读取任何字节,read()返回零.
如果count为零,则read()可以检测下面描述的错误.在没有任何错误的情况下,或者read()没有检查错误时,计数为0的read()返回零并且没有其他影响.
如果count大于SSIZE_MAX,则结果未指定.
所以我的问题是,为什么会发生这种行为?Linux内核中的规范是否应该发生这种情况还是其他内容的结果?
我曾经到Linux USB端口命名,又名的/ dev/ttyUSBxx,目前尝试写一些测试软件对iMac的读/ wrtie原始数据到USB端口,但我觉得很难检测到我的USB硬件连接的端口.我尝试过使用/ dev/ttys"x",但没有运气.
在系统信息中,我看到位置ID附带的硬件:0xfa120000/6也许这可以帮助某种程度?
我正在使用两个Wavecom 16端口调制解调器.当我将调制解调器连接到我的系统时,我能够列出所有/dev/ttyUSB端口名称,但我也想知道,哪个调制解调器包含端口0到16,哪个包含端口17到32?
调制解调器可以在一天内连接和删除多次,因此我还希望在调制解调器断开连接并再次连接时保留日志.
知道怎么用c/c ++/php script/node.js吗?
Java - Jsch sudo命令.
我正在使用Jsch,我的任务是登录服务器并运行命令,如下所示
sudo su - bumboo
Run Code Online (Sandbox Code Playgroud)
使用以下代码我成功连接,但当我尝试运行命令时,它给了我错误 sudo: sorry, you must have a tty to run sudo
以下是我的代码
public static Channel sudoBamboo(Session session, String sudo_pass) throws Exception {
ChannelExec channel = (ChannelExec) session.openChannel("exec");
//SUDO to bamboo user
String command = "sudo su - bumboo";
channel.setCommand(command);
//InputStream in = channel.getInputStream();
channel.setInputStream(null, true);
OutputStream out = channel.getOutputStream();
//channel.setErrStream(System.err);
channel.setOutputStream(System.out, true);
channel.setExtOutputStream(System.err, true);
//Test change
//channel.setPty(false);
channel.connect();
out.write((sudo_pass + "\n").getBytes());
out.flush();
return channel;
}
Run Code Online (Sandbox Code Playgroud)
他们建议使用sudo.java中的jsch
// man sudo
// -S …Run Code Online (Sandbox Code Playgroud) 我有一个需要 tty (如 stdin 和 stderr)的可执行文件,并且希望能够测试它。我想输入 stdin,并捕获 stdout 和 stderr 的输出,这是一个示例脚本:
# test.py
import sys
print("stdin: {}".format(sys.stdin.isatty()))
print("stdout: {}".format(sys.stdout.isatty()))
print("stderr: {}".format(sys.stderr.isatty()))
sys.stdout.flush()
line = sys.stdin.readline()
sys.stderr.write("read from stdin: {}".format(line))
sys.stderr.flush()
Run Code Online (Sandbox Code Playgroud)
我可以在没有 tty 的情况下运行它,但是它会被捕获.isatty并且每个都返回 False:
import subprocess
p = subprocess.Popen(["python", "test.py"], stdin=subprocess.PIPE, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
p.stdin.write(b"abc\n")
print(p.communicate())
# (b'stdin: False\nstdout: False\nstderr: False\n', b'read from stdin: abc\n')
Run Code Online (Sandbox Code Playgroud)
我想捕获 stdout 和 stderr 并让所有三个返回 True - 作为 tty。
我可以用来pty制作 tty 标准输入:
import subprocess
m, s = pty.openpty()
p = subprocess.Popen(["python", "test.py"], …Run Code Online (Sandbox Code Playgroud) 在 docker 中,我可以简单地使用-t开关来docker run分配伪 tty(在这些示例中,我使用它nohup与真实 tty 分离):
$ nohup docker run debian tty # Produces "not a tty"
$ nohub docker run -t debian tty # Produces "/dev/pts/0"
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用 docker-compose 达到相同的结果。我有以下内容docker-compose.yml:
version: "3"
services:
myservice:
image: debian
tty: true
Run Code Online (Sandbox Code Playgroud)
我运行它有和没有nohup:
$ docker-compose run myservice tty # Produces "/dev/pts/0"
$ nohup docker-compose run myservice tty # Produces "not a tty"
Run Code Online (Sandbox Code Playgroud)
的文档docker-compose run说我可以用来-T禁用伪 tty的分配,但似乎没有一种方法可以显式地启用它(这不是必需的,因为默认情况下应该分配一个tty)。
-T …