我希望能够在启动交互式进程时注入初始命令,以便我可以执行以下操作:
echo "initial command" | INSERT_MAGIC_HERE some_tool
tool> initial command
[result of initial command]
tool> [now I type an interactive command]
Run Code Online (Sandbox Code Playgroud)
什么行不通:
只是管道输入初始命令不起作用,因为这导致stdin没有连接到终端
写入/ dev/pts/[number]将输出发送到终端,而不是输入到进程,就像它来自终端一样
什么会有缺点:
创建一个分叉子命令,写入stdin,然后从自己的stdin转发所有内容.下行 - 终端控制事物(如线与字符模式)不起作用.也许我可以用代理伪终端做些什么?
使用命令行选项创建xterm的修改版本(我正在为此任务启动一个),以在遇到所需的提示字符串后注入其他命令.丑陋.
制作我正在尝试运行的工具的修改版本,以便它在命令行上接受初始命令.打破标准安装.
(顺便提一下,当前感兴趣的工具是android的adb shell - 我想在手机上打开一个交互式shell,自动运行命令,然后进行交互式会话)
我有一些bash函数输出一些信息:
我一直在编写读取输出和过滤它的函数:
function filter-epson {
find-modelname-in-epson-ppds | sed <bla-blah-blah>
}
function filter-hp {
find-modelname-in-hp-ppds | sed <the same bla-blah-blah>
}
etc ...
Run Code Online (Sandbox Code Playgroud)
但我认为最好做这样的事情:
function filter-general {
(somehow get input) | sed <bla-blah-blah>
}
Run Code Online (Sandbox Code Playgroud)
然后调用另一个高级函数:
function high-level-func {
# outputs filtered information
find-modelname-in-hp/epson/...-ppds | filter-general
}
Run Code Online (Sandbox Code Playgroud)
如何通过最好的bash实践实现这一目标?
我需要你的帮助,我正试图从我的火力显示器中显示一些数据,但它却给我一个错误InvalidPipeArgument: '[object Object]' for pipe 'AsyncPipe'.
有我的服务:
import { Injectable } from '@angular/core';
import { AngularFireDatabase } from 'angularfire2/database';
@Injectable()
export class MoviesService {
constructor(private db: AngularFireDatabase) {}
get = () => this.db.list('/movies');
}
Run Code Online (Sandbox Code Playgroud)
有我的组件:
import { Component, OnInit } from '@angular/core';
import { MoviesService } from './movies.service';
@Component({
selector: 'app-movies',
templateUrl: './movies.component.html',
styleUrls: ['./movies.component.css']
})
export class MoviesComponent implements OnInit {
movies: any[];
constructor(private moviesDb: MoviesService) { }
ngOnInit() {
this.moviesDb.get().subscribe((snaps) => {
snaps.forEach((snap) => {
this.movies …Run Code Online (Sandbox Code Playgroud) 我正在从网上抓取数据,并且我有几个并行运行刮刀的过程.
我希望每个进程的输出最终都在同一个文件中.只要文本行保持完整并且不会相互混淆,行的顺序无关紧要.在UNIX中,我可以使用>>运算符将每个进程的输出管道传输到同一个文件吗?
我需要获取.wav文件的长度.
使用:
sox output.wav -n stat
Run Code Online (Sandbox Code Playgroud)
得到:
Samples read: 449718
Length (seconds): 28.107375
Scaled by: 2147483647.0
Maximum amplitude: 0.999969
Minimum amplitude: -0.999969
Midline amplitude: 0.000000
Mean norm: 0.145530
Mean amplitude: 0.000291
RMS amplitude: 0.249847
Maximum delta: 1.316925
Minimum delta: 0.000000
Mean delta: 0.033336
RMS delta: 0.064767
Rough frequency: 660
Volume adjustment: 1.000
Run Code Online (Sandbox Code Playgroud)
如何使用grep或其他方法仅输出第二列中的长度值,即28.107375?
谢谢
我正在尝试将cat输出传递给curl:
$ cat file | curl --data '{"title":"mytitle","input":"-"}' http://api
Run Code Online (Sandbox Code Playgroud)
但input实际上是一个-.
我有一个程序将文本发送到LED标志.
prismcom.exe
要使用该程序发送"Hello":
prismcom.exe usb Hello
Run Code Online (Sandbox Code Playgroud)
现在,我希望使用一个名为Temperature的命令程序.
temperature
Run Code Online (Sandbox Code Playgroud)
假设程序给出了计算机的温度.
Your computer is 100 degrees Fahrenheit.
Run Code Online (Sandbox Code Playgroud)
现在,我希望将温度输出写入prismcom.exe:
temperature | prismcom.exe usb
Run Code Online (Sandbox Code Playgroud)
这似乎不起作用.
是的,我已经找了20多分钟的解决方案了.在所有情况下,它们都是kludges/hacks或Windows命令行之外的解决方案.
我很欣赏如何将输出从温度传输到prismcom的方向.
谢谢!
编辑:Prismcom有两个论点.第一个将永远是'usb'.之后发生的任何事情都会显示在标志上.
我需要date | grep -o -w '"+tz+"'' | wc -w在我的localhost上使用Python 运行命令 .我正在使用subprocess相同的模块,并使用check_output我需要捕获输出相同的方法.
但是它给我一个错误:
Traceback (most recent call last):
File "test.py", line 47, in <module>
check_timezone()
File "test.py", line 40, in check_timezone
count = subprocess.check_output(command)
File "/usr/lib/python2.7/subprocess.py", line 537, in check_output
process = Popen(stdout=PIPE, *popenargs, **kwargs)
File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1249, in _execute_child
raise child_exception-
OSError: [Errno 2] No such file or directory
Run Code Online (Sandbox Code Playgroud)
请帮助我哪里出错了.我是python的新手
我想传递一个密码来ssh使用bash脚本(是的,我知道我可以使用ssh密钥,但这不是我想要的).
我找到了一些正在使用的解决方案,expect但由于它不是标准的bash工具,我想知道我是否可以使用管道来做到这一点.
有人可以向我解释,为什么会这样:
echo "password\n" | ssh somehost.com
Run Code Online (Sandbox Code Playgroud)
要么
ssh somehost.com <(echo "password\n")
Run Code Online (Sandbox Code Playgroud)
不起作用?有没有可能使它工作?也许ssh作为一个不同的进程执行,获取它的PID,然后直接发送一个字符串给它?
我正在用python测试子进程管道.我知道我可以直接在python中执行下面的程序,但这不是重点.我只是想测试管道,所以我知道如何使用它.
我的系统是Linux Ubuntu 9.04,默认为python 2.6.
我从这个文档示例开始.
from subprocess import Popen, PIPE
p1 = Popen(["grep", "-v", "not"], stdout=PIPE)
p2 = Popen(["cut", "-c", "1-10"], stdin=p1.stdout, stdout=PIPE)
output = p2.communicate()[0]
print output
Run Code Online (Sandbox Code Playgroud)
这样的作品,但由于p1的stdin不被重定向,我在终端类型的东西喂管.当我输入^D关闭stdin时,我得到了我想要的输出.
但是,我想使用python字符串变量将数据发送到管道.首先我尝试写stdin:
p1 = Popen(["grep", "-v", "not"], stdin=PIPE, stdout=PIPE)
p2 = Popen(["cut", "-c", "1-10"], stdin=p1.stdout, stdout=PIPE)
p1.stdin.write('test\n')
output = p2.communicate()[0] # blocks forever here
Run Code Online (Sandbox Code Playgroud)
没工作.我尝试p2.stdout.read()在最后一行使用,但它也阻止.我补充说p1.stdin.flush(),p1.stdin.close()但它也没有用.我然后我开始沟通:
p1 = Popen(["grep", "-v", "not"], stdin=PIPE, stdout=PIPE)
p2 = Popen(["cut", "-c", "1-10"], …Run Code Online (Sandbox Code Playgroud) pipe ×10
bash ×2
linux ×2
python ×2
shell ×2
subprocess ×2
unix ×2
angular ×1
angularfire2 ×1
audio ×1
blocking ×1
concurrency ×1
curl ×1
grep ×1
ipc ×1
observable ×1
pug ×1
sox ×1
wav ×1
windows ×1