piping

Unix pipe - reading data from stdin in the child descriptor

不羁的心 提交于 2019-12-22 17:47:16
问题 I'm trying to implement unix piping in c (i.e. execute ls | wc). I have found a related solution to my problem (C Unix Pipes Example) however, I am not sure why a specific portion of the solved code snippet works. Here's the code: /* Run WC. */ int filedes[2]; pipe(filedes); /* Run LS. */ pid_t pid = fork(); if (pid == 0) { /* Set stdout to the input side of the pipe, and run 'ls'. */ dup2(filedes[1], 1); char *argv[] = {"ls", NULL}; execv("/bin/ls", argv); } else { /* Close the input side of

PowerShell ForEach / Piping confusion

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-22 03:54:08
问题 I am using the TFS PowerTools Cmdlets in PowerShell to try to get at some information about Changesets and related WorkItems from my server. I have boiled the problem down to behavior I don't understand and I am hoping it is not TFS specific (so someone out there might be able to explain the problem to me :) ) Here's the only command that I can get to work: Get-TfsItemHistory C:\myDir -recurse -stopafter 5 | % { Write-Host $_.WorkItems[0]["Title"] } It does what I expect - Get-TfsItemHistory

PHP - Filtering Email Body, Removing Reply Quotes

心不动则不痛 提交于 2019-12-18 11:55:51
问题 I'm working on an email piping script that needs to save just the reply content and not the original quoted email. I'm using a mime parser class (http://www.phpclasses.org/package/3169-PHP-Decode-MIME-e-mail-messages.html) to get all the information that I need from the email: Message ID: AANLkTimYRxMJwjLSdcDP5ksM=xxx@mail.gmail.com Reply ID: 20110316205225.xxx@example.com Subject: Re: MessageX To: q1-1234567890@example.com From: Someone someone@someothersite.com Body: Hello, Blah Blah Blah

Redirecting arguments into a program (BASH)

允我心安 提交于 2019-12-18 09:47:37
问题 I am fairly new to bash scripting and a part I am stuck on is after done< "$file_input" What I am trying to achieve is when I run the program ./test inside the testfile contains the numbers 15 14 90 22 and the program is going to take those numbers as the arguments and run it, but I am quite unsure how to do that. Am I going in the correct direction? Thanks for any help if [[ "$#" -ne 1 ]] then writeusage exit fi your_path=../file/test test_path=../../public/test file_input="$1" while read -r

Chain arithmetic operators in dplyr with %>% pipe

可紊 提交于 2019-12-18 04:29:20
问题 I would like to understand why, in the the dplyr or magrittr package, and more specifically the chaining function %>% has some trouble with the basic operators + , - , * , and / Chaining takes the output of previous statement and feeds it as first argument of the next: 1:10 %>% sum # [55] Thus how come this doesn't work 1:10 %>% *2 %>% sum 1:10 %>% .*2 %>% sum I also found that the following syntax works for adding/substracting, but not multiply or divide. why so? 1:10 %>% +(2) # works OK 1

Piping both stdout and stderr in bash?

久未见 提交于 2019-12-17 07:04:33
问题 It seems that newer versions of bash have the &> operator, which (if I understand correctly), redirects both stdout and stderr to a file ( &>> appends to the file instead, as Adrian clarified). What's the simplest way to achieve the same thing, but instead piping to another command? For example, in this line: cmd-doesnt-respect-difference-between-stdout-and-stderr | grep -i SomeError I'd like the grep to match on content both in stdout and stderr (effectively, have them combined into one

Why piping input to “read” only works when fed into “while read …” construct? [duplicate]

风格不统一 提交于 2019-12-17 04:45:42
问题 This question already has answers here : Read values into a shell variable from a pipe (15 answers) Closed 5 months ago . I've been trying to read input into environment variables from program output like this: echo first second | read A B ; echo $A-$B And the result is: - Both A and B are always empty. I read about bash executing piped commands in sub-shell and that basically preventing one from piping input to read. However, the following: echo first second | while read A B ; do echo $A-$B

Why piping input to “read” only works when fed into “while read …” construct? [duplicate]

流过昼夜 提交于 2019-12-17 04:45:27
问题 This question already has answers here : Read values into a shell variable from a pipe (15 answers) Closed 5 months ago . I've been trying to read input into environment variables from program output like this: echo first second | read A B ; echo $A-$B And the result is: - Both A and B are always empty. I read about bash executing piped commands in sub-shell and that basically preventing one from piping input to read. However, the following: echo first second | while read A B ; do echo $A-$B

Numeric calculations using dplyr piping commands

时光总嘲笑我的痴心妄想 提交于 2019-12-13 20:22:58
问题 Is it possible to use piping from the dplyr package to do numeric calculations? A simple example is: 0.15 %>% 3.8416 * (.*(1-.))/(0.03^2) #does not work seq(1,10,1) %>% log(.) %>% .^2 #works Tying to understand more of how piping works and when it can and cannot be used. I really enjoy using the piping feature and want to find a way to use it for these types of numeric calculations. Many thanks 回答1: You have an operator precedence problem. It's trying to start by doing 0.15 %>% 3.8416 which

Pipe result from subprocess to unix sort

霸气de小男生 提交于 2019-12-12 02:27:18
问题 I am calling a perl script on an external txt files from python, and printing the output to an outfile. But instead I want to pipe the output to unix's sort. Right now I am not piping, but are writing the output from the perl program first, then doing by combining my code under, and this stackoverflow answer. import subprocess import sys import os for file in os.listdir("."): with open(file + ".out", 'w') as outfile: p = subprocess.Popen(["perl", "pydyn.pl", file], stdout=outfile) p.wait()