pipe

Piping data from child to parent in nodejs

坚强是说给别人听的谎言 提交于 2020-01-12 04:56:05
问题 I have a nodejs parent process that starts up another nodejs child process. The child process executes some logic and then returns output to the parent. The output is large and I'm trying to use pipes to communicate, as suggested in documentation for child.send() method (which works fine BTW). I would like someone to suggest how to properly build this communication channel. I want to be able to send data from parent to child and also to be able to send data from child to parent. I've started

Python实现cmd命令连续执行

女生的网名这么多〃 提交于 2020-01-12 02:07:36
之前是想写一个微信控制程序,通过登录网页微信,可以直接执行命令行代码。也不用ssh登录了,想法很方便。 但是现实很残酷,微信登录这块基本没有问题,已经有大佬写好了,但是命令行执行遇到问题了。 运行cmd 开始时,使用os.popen()执行命令,但是该命令需要手动修改运行目录。此方案被我直接丢弃了。 单开进程 那么自然想到通过启动进程的方式来实现,Python有对进程的封装 subprocess ,可以通过创建Popen对象来实现。我只要单开一个bash,与它进行交互就好啦。 简单实现如下: ​ p = subprocess.Popen('/bin/bash', shell=True, stdin=subprocess.PIPE, stderr=subprocess.PIPE, stdout=subprocess.PIPE) ​ while True: c = input() c += os.linesep p.stdin.write(c.encode('utf8')) print(out_s.decode('utf8'), end='') 然后,马上就有遇到问题了,输出流一直拿不到内容,被阻塞了。 刷新缓冲区 被阻塞有两种情况,一输入流阻塞,所以没有输出,二输出流阻塞。看到网上有的将输入流关闭就可以了: p.stdin.close() 但是关闭后就不能再次运行命令了

How can I read piped input in Perl on Windows?

微笑、不失礼 提交于 2020-01-11 18:52:29
问题 I am trying to create something in Perl that is basically like the Unix tee command. I'm trying to read each line of STDIN , run a substitution on it, and print it. (And eventually, also print it to a file.) This works if I'm using console input, but if I try to pipe input to the command it doesn't do anything. Here's a simple example: print "about to loop\n"; while(<STDIN>) { s/2010/2009/; print; } print "done!\n"; I try to pipe the dir command to it like this: C:\perltest>dir | mytee.pl

node.js : how to pipe - youtube to mp4 to mp3

本小妞迷上赌 提交于 2020-01-11 17:31:25
问题 I want to convert a youtube url into an mp3 file. Currently, I download the mp4 using node's ytdl module, like so: fs = require 'fs' ytdl = require 'ytdl' url = 'http://www.youtube.com/watch?v=v8bOTvg-iaU' mp4 = './video.mp4' ytdl(url).pipe(fs.createWriteStream(mp4)) Once the download is complete, I convert the mp4 into mp3 using the fluent-ffmpeg module, like so: ffmpeg = require 'fluent-ffmpeg' mp4 = './video.mp4' mp3 = './audio.mp3' proc = new ffmpeg({source:mp4}) proc.setFfmpegPath('

Python subprocess Popen: Send binary data to C++ on Windows

孤街浪徒 提交于 2020-01-11 11:58:16
问题 After three days of intensive googleing and stackoverflowing I more or less got my program to work. I tried a lot of stuff and found a lot of answers somehow connected to my problem, but no working solution. Sry should I have missed the right page!! I'm looking forward to comments and recommendations. Task: Send binary data (floats) from python to C++ program, get few floats back Data is going to be 20ms soundcard input, latency is a bit critical Platform: Windows (only due to drivers for the

How to pipe the output of a command to a file without powershell changing the encoding?

谁说我不能喝 提交于 2020-01-11 10:11:41
问题 I want to pipe the output of a command to a file: PS C:\Temp> create-png > binary.png I noticed that Powershell changes the encoding and that I can manually give an encoding: PS C:\Temp> create-png | Out-File "binary.png" -Encoding OEM However there is no RAW encoding option, even the OEM option changes newline bytes ( 0xA resp 0xD ) to the windows newline byte sequence ( 0xD 0xA ) thereby ruining any binary format. How can I prevent Powershell from changing the encoding when piping to a file

How to pipe the output of a command to a file without powershell changing the encoding?

天涯浪子 提交于 2020-01-11 10:09:06
问题 I want to pipe the output of a command to a file: PS C:\Temp> create-png > binary.png I noticed that Powershell changes the encoding and that I can manually give an encoding: PS C:\Temp> create-png | Out-File "binary.png" -Encoding OEM However there is no RAW encoding option, even the OEM option changes newline bytes ( 0xA resp 0xD ) to the windows newline byte sequence ( 0xD 0xA ) thereby ruining any binary format. How can I prevent Powershell from changing the encoding when piping to a file

How to redirect grep output to a variable?

怎甘沉沦 提交于 2020-01-11 09:30:11
问题 I have some pipe. For example, I have this pipe: user@user:~$ cal | head -1 | grep -oP "[A-Za-z]+" For this pipe I get this result: September I want to store this result to a variable. I write the following commands: user@user:~$ cal | head -1 | month=$(grep -oP "[A-Za-z]+") | echo $month And I get the blank string. What is the problem? 回答1: month=$(cal | head -1 | grep -oP "[A-Za-z]+") or month=$(date +%B) 来源: https://stackoverflow.com/questions/25710640/how-to-redirect-grep-output-to-a

grep with continuous pipe does not work

吃可爱长大的小学妹 提交于 2020-01-11 09:23:09
问题 (maybe it is the "tcpflow" problem) I write a script to monitoring http traffic, and I install tcpflow , then grep it works (and you should make a http request, for example curl www.163.com ) sudo tcpflow -p -c -i eth0 port 80 2>/dev/null | grep '^Host: ' it outputs like this (continuously) Host: config.getsync.com Host: i.stack.imgur.com Host: www.gravatar.com Host: www.gravatar.com but I can't continue to use pipe does not work (nothing output) sudo tcpflow -p -c -i eth0 port 80 2>/dev/null

grep with continuous pipe does not work

你。 提交于 2020-01-11 09:23:06
问题 (maybe it is the "tcpflow" problem) I write a script to monitoring http traffic, and I install tcpflow , then grep it works (and you should make a http request, for example curl www.163.com ) sudo tcpflow -p -c -i eth0 port 80 2>/dev/null | grep '^Host: ' it outputs like this (continuously) Host: config.getsync.com Host: i.stack.imgur.com Host: www.gravatar.com Host: www.gravatar.com but I can't continue to use pipe does not work (nothing output) sudo tcpflow -p -c -i eth0 port 80 2>/dev/null