piping

How to output bash command to stdout and pipe to another command at the same time?

五迷三道 提交于 2019-12-11 23:38:16
问题 I'm working on a server and to show detailed GPU information I use these commands: nvidia-smi ps -up `nvidia-smi |tail -n +16 | head -n -1 | sed 's/\s\s*/ /g' | cut -d' ' -f3` However as you can see, nvidia-smi is called twice. How can I make the output of nvidia-smi go to output and pipe to another command at the same time? 回答1: Use tee : ps -up `nvidia-smi |tee /dev/stderr |tail -n +16 | head -n -1 | sed 's/\s\s*/ /g' | cut -d' ' -f3` Since stdout is piped, you can't make a copy to it, so I

piping standard output into QLabel in Qt 4.7

懵懂的女人 提交于 2019-12-11 14:44:34
问题 I am trying to wrap a colleges c++ code in a Qt widget. However, his programs std output necessarily needs to be viewed. As of now I am assuming I will build a GUI and open a QProccess that will run his program (then send commands over that pipe). So my question is there anyway to read the standard output of that program and display it in a qlabel or something similar (i.e. what functions should I be looking into)? 回答1: As the process runs, the QProcess object will emit the

F# piping to/from .net objects

橙三吉。 提交于 2019-12-11 04:46:57
问题 I've noticed difficulty in piping to/from some .NET methods. Toy example let foo = System.String [| 'a'; 'b'; 'c' |] // works let foo = [| 'a'; 'b'; 'c' |] |> System.String // fails // error FS0802: Invalid use of a type name and/or object constructor. let foo = System.String <| [| 'a'; 'b'; 'c' |] // fails the same way let foo = [| 'a'; 'b'; 'c' |] |> new System.String // Fails // error FS0010: Incomplete structured construct at or before this point in expression I'm basically trying to

Python script using subprocess and xclip hangs if piped in bash

老子叫甜甜 提交于 2019-12-11 01:58:56
问题 I have a python script that needs to output some values to stdin and copies another string to clipboard. I'm using the module subprocess to execute the xclip utility through Popen something like this: # clip.py import subprocess from subprocess import Popen print('PRINT_ME') p1 = Popen(['xclip', '-selection', 'clipboard'], stdin=subprocess.PIPE) p1.communicate(input=('PASTE_ME'.encode())) The script works as intended: PRINT_ME is echoed in bash and PASTE_ME is available to paste, and returns

Problem with piping commands in C

偶尔善良 提交于 2019-12-10 01:59:08
问题 I'm trying to create a simple shell in C for Unix. I've been able to do all the parsing of commands and execution, but I'm having a problem with piping. I think the problem is that I'm not hooking into the correct pipe for the input of the second command. For example, if I type "ls | wc", it will pause after the "wc" command, which I think is because its waiting for input. I think the problem is when I use dup2(reading[i],0), and its not hooking into the correct pipe. I know this is a bit of

Python: replacing shell pipeline with an ssh connection

拈花ヽ惹草 提交于 2019-12-09 03:34:25
I have the following nice bash command : cat SomePythonScript.py | ssh remote_machine 'cat - | python' that works very fine and that I want to write in Python. I tried with 'subprocess' but did not get that far. Can someone help me ? from subprocess import PIPE , Popen p1 = Popen(["cat ", "SomePythonScript.py"], stdout=PIPE) p2 = Popen(["remote_machine"], stdin=p1.stdout, stdout=PIPE) p3 = Popen(["cat -", "python"], stdin=p2.stdout, stdout=PIPE) p1.stdout.close() p2.stdout.close() output = p3.communicate()[0] I tried also with 2 processes/ pipes from subprocess import PIPE , Popen p1 = Popen([

Python: replacing shell pipeline with an ssh connection

柔情痞子 提交于 2019-12-08 07:20:52
问题 I have the following nice bash command : cat SomePythonScript.py | ssh remote_machine 'cat - | python' that works very fine and that I want to write in Python. I tried with 'subprocess' but did not get that far. Can someone help me ? from subprocess import PIPE , Popen p1 = Popen(["cat ", "SomePythonScript.py"], stdout=PIPE) p2 = Popen(["remote_machine"], stdin=p1.stdout, stdout=PIPE) p3 = Popen(["cat -", "python"], stdin=p2.stdout, stdout=PIPE) p1.stdout.close() p2.stdout.close() output = p3

crossfading a group of audio files with sox splice

我们两清 提交于 2019-12-07 07:49:29
问题 I am able to join and crossfade two audio files using SoX, like so: sox file1.wav file2.wav outfile.wav splice -q `soxi -D file1.wav`,0.5 where the soxi substitution is fetching the duration of file1 and 0.5 is the length of the cross-fade. I am now trying to extend this to an arbitrary number of files, in order to string them together with short crossfades in between. There would seem to be 2 approaches: piping and scripting. Sox has a -p option telling it to treat it's output as piped

passing paremeters from PHP Email piping

妖精的绣舞 提交于 2019-12-06 16:19:09
I have a PHP Script that received information from a piped email forwarder. Currently everything works perfectly. I just want to manipulate the received parameters to receive only the data I want from the email the script is: #!/usr/local/bin/php -q <?PHP //get email $fd = fopen("php://stdin", "r"); $email_content = ""; while (!feof($fd)) { $email_content .= fread($fd, 1024); } fclose($fd); //get email end //get variables from email start //split the string into array of strings, each of the string represents a single line, recieved $lines = explode("\n", $email_content); // initialize

Unix pipe - reading data from stdin in the child descriptor

一曲冷凌霜 提交于 2019-12-06 10:36:52
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 the pipe, to prevent it staying open. */ close(filedes[1]); } /* Run WC. */ pid = fork(); if (pid ==