pipe

Pipe commands with fork and dup2

≯℡__Kan透↙ 提交于 2020-04-18 03:57:11
问题 I wrote the following code in order to pipe two commands: #include <stdlib.h> #include <unistd.h> char *program_1[3] = {"/bin/cat", "/dev/random", NULL}; char *program_2[2] = {"/bin/ls", NULL}; char *program_3[2] = {"/usr/bin/sort", NULL}; int main(void) { int fd[2]; int pid; pipe(fd); if ((pid = fork()) == 0) //Child process { dup2(fd[1], STDOUT_FILENO); close(fd[0]); execve(program_3[0], program_3, NULL); } else if (pid > 0) //Parent process { dup2(fd[0], STDIN_FILENO); close(fd[1]); execve

Piping data from a python script into a .csv or .txt file

余生颓废 提交于 2020-04-17 19:01:08
问题 I want to monitor air quality inside my flat (downstairs neighbor is an avid smoker). For so doing, I have a Raspberry Pie 3 Model B+ connected with an Enviro+. While in the terminal I can run the script that measures small particles. python particulates.py cf. https://github.com/pimoroni/enviroplus-python/blob/master/examples/particulates.py It then runs and display the data in the terminal, like in the picture below: (yes, I am better at lego-ing, than coding). I am interested in keeping a

Piping data from a python script into a .csv or .txt file

痴心易碎 提交于 2020-04-17 19:00:24
问题 I want to monitor air quality inside my flat (downstairs neighbor is an avid smoker). For so doing, I have a Raspberry Pie 3 Model B+ connected with an Enviro+. While in the terminal I can run the script that measures small particles. python particulates.py cf. https://github.com/pimoroni/enviroplus-python/blob/master/examples/particulates.py It then runs and display the data in the terminal, like in the picture below: (yes, I am better at lego-ing, than coding). I am interested in keeping a

Removing progress bar from program output redirected into log file

吃可爱长大的小学妹 提交于 2020-04-16 05:49:30
问题 I was running a program, and it will output the progress bar. I did it like this python train.py |& tee train.log The train.log looks like the following. This is line 1 Training ... This is line 2 ... [000] valid: 100%|█████████████████████████████████████████████████████████████▉| 2630/2631 [15:24<00:00, 2.98 track/s] [000] valid: 100%|██████████████████████████████████████████████████████████████| 2631/2631 [15:25<00:00, 3.02 track/s] Epoch 000: train=0.11940351 valid=0.10640465 best=0.1064

ffmpeg output pipeing to named windows pipe

旧时模样 提交于 2020-04-10 14:50:35
问题 This question is related to my previous question: Converting raw frames into webm live stream I want to pipe a video to ffmpeg and read it back through another pipe, but I cannot pipe the output of ffmpeg.exe to a named pipe on windows. My definition of the pipes in C#: NamedPipeServerStream p_to_ffmpeg; NamedPipeServerStream p_from_ffmpeg; p_to_ffmpeg = new NamedPipeServerStream("to_ffmpeg", PipeDirection.Out, 1, PipeTransmissionMode.Byte); p_from_ffmpeg = new NamedPipeServerStream("from

ffmpeg output pipeing to named windows pipe

一笑奈何 提交于 2020-04-10 14:48:46
问题 This question is related to my previous question: Converting raw frames into webm live stream I want to pipe a video to ffmpeg and read it back through another pipe, but I cannot pipe the output of ffmpeg.exe to a named pipe on windows. My definition of the pipes in C#: NamedPipeServerStream p_to_ffmpeg; NamedPipeServerStream p_from_ffmpeg; p_to_ffmpeg = new NamedPipeServerStream("to_ffmpeg", PipeDirection.Out, 1, PipeTransmissionMode.Byte); p_from_ffmpeg = new NamedPipeServerStream("from

IPC: UWP C# pipe client fails on connect C++ server

ε祈祈猫儿з 提交于 2020-04-07 08:33:06
问题 I am trying to use NamedPipe to communicate between app and service in Win10. APP is developed with C#(UWP),running foreground as Pipe Client. And service is C++ running background as Pipe Server. Now the problem is that the APP couldn't connect the service. I know that MSFT doc said Pipes are only supported within an app-container. But I have tried the following cases: my uwp app VS C#(nonUWP) Server(not in an app-container); C++ Client VS C++ server(same code with service except running in

Why does `timeout` not work with pipes?

时光怂恿深爱的人放手 提交于 2020-04-06 08:29:27
问题 The following command line call of timeout (which makes no sense, just for testing reason) does not work as expected. It waits 10 seconds and does not stop the command from working after 3 seconds. Why ? timeout 3 ls | sleep 10 回答1: What your command is doing is running timeout 3 ls and piping its output to sleep 10 . The sleep command is therefore not under the control of timeout and will always sleep for 10s. Something like this would give the desired effect. timeout 3 bash -c "ls | sleep

Why does `timeout` not work with pipes?

|▌冷眼眸甩不掉的悲伤 提交于 2020-04-06 08:28:21
问题 The following command line call of timeout (which makes no sense, just for testing reason) does not work as expected. It waits 10 seconds and does not stop the command from working after 3 seconds. Why ? timeout 3 ls | sleep 10 回答1: What your command is doing is running timeout 3 ls and piping its output to sleep 10 . The sleep command is therefore not under the control of timeout and will always sleep for 10s. Something like this would give the desired effect. timeout 3 bash -c "ls | sleep

suprocess模块

扶醉桌前 提交于 2020-04-01 06:02:15
suprocess模块 import subprocess ''' sh-3.2# ls /Users/egon/Desktop |grep txt$ mysql.txt tt.txt 事物.txt ''' res1=subprocess.Popen('ls /Users/jieli/Desktop',shell=True,stdout=subprocess.PIPE) res=subprocess.Popen('grep txt$',shell=True,stdin=res1.stdout, stdout=subprocess.PIPE,stderr=subprocess.PIPE) # 此处是否为utf-8要看系统的默认编码,必须输入系统编码格式 print(res.stdout.read().decode('utf-8')) print(res.stderr.read().decode('utf-8')) #等同于上面,但是上面的优势在于,一个数据流可以和另外一个数据流交互,可以通过爬虫得到结果然后交给grep res1=subprocess.Popen('ls /Users/jieli/Desktop |grep txt$',shell=True,stdout=subprocess.PIPE) print(res1.stdout.read().decode('utf-8')