pipe

How to use popen?

你。 提交于 2019-12-24 07:29:16
问题 I'm trying to do inter process communication with stdin and stdout . The Posix function I found is popen , but I failed to write a working sample code. Please help me get this work. <edit1> Do I have to use dup ? I can see some examples found with Google using it. But the Linux manual of dup really does not help me understanding how to use that. </edit1> a.c #include <stdio.h> #include <stdlib.h> #include <string.h> int main(void){ char *s; for(;;){ scanf("%ms",&s); printf("%s\n",s); if(

Pipe function not executing properly

自作多情 提交于 2019-12-24 07:17:39
问题 I have constructed the following program to try to pipe in my own shell. A StringArray is simply a char** I have constructed. The code runs fine, but when I put in cat txt.txt | grep a , nothing prints back to the screen. When debugging, I saw that the code seems to stop around like 152 (where the print-out command is), where pid==0 and i==0 . For context, I'm calling this function in another function after a pipe has been detected. void doPipe(StringArray sa) { printf("In 69\n"); int filedes

Forking a new process in C++ and executing a .jar file

人盡茶涼 提交于 2019-12-24 06:34:42
问题 I am attempting to write a program that will read the output from a java .jar file and also give it input from time to time. Basically I am hoping to make a program that will execute certain functions when certain output is encountered. The .jar file wasn't created by me, and I don't have the source code, so I have to use it as-is. After doing some research I decided using fork() and execl() in conjunction with pipes was the method I would need to use and I created a small program that

distinguish stdout from stderr on pipe

最后都变了- 提交于 2019-12-24 05:32:49
问题 popen() alternative My question is related to one posted above. In the first/accepted response, we are doing: // Child. Let's redirect its standard output to our pipe and replace process with tail close(pipefd[0]); dup2(pipefd[1], STDOUT_FILENO); dup2(pipefd[1], STDERR_FILENO); But what I want is to distinguish ERROR from regular OUTPUT . How can I do that? When I get anything in STDERR, I need to react to it. It does not make much sense but, can I do following?: int pipefd[3] /* instead of 2

How to avoid read() from hanging in the following situation?

邮差的信 提交于 2019-12-24 05:26:15
问题 I have some code that forks a third-party application and redirects its standard output to the parent process, roughly as follows (no error handling here for brevity): char* args[] = {"/path/to/3rd/party/binary", "with", "args", NULL}; int fds[2]; pipe2(fds, O_CLOEXEC); pid_t pid = fork(); if (pid == 0) { dup2(fds[1], STDOUT_FILENO); execvp(args[0], args); _exit(1); } else { close(fds[1]); char buf[1024]; int bytes_read; while ((bytes_read = read(fds[0], buf, sizeof buf - 1)) > 0) { buf[bytes

angular2 – use global service through a custom pipe

风格不统一 提交于 2019-12-24 04:54:13
问题 I am playing around a little bit with angular 2. So far I built a global service that holds an interface. Other components are using the interface of this global service. If the interface is changed through a component the interface will also change for the child components. Now I am trying to handle this through a pipe. But when I am changing the interface value through a child component the interface values within the other components won't change. This is what I got so far: import { Pipe,

Python script not waiting for user input when ran from piped bash script

拥有回忆 提交于 2019-12-24 04:31:52
问题 I am building an interactive installer using a nifty command line: curl -L http://install.example.com | bash The bash script then rapidly delegates to a python script: # file: install.sh [...] echo "-=- Welcome -=-" [...] /usr/bin/env python3 deploy_p3k.py And the python script itself prompts the user for input: # file: deploy_py3k.py [...] input('====> Confirm or enter installation directory [/srv/vhosts/project]: ') [...] input('====> Confirm installation [y/n]: ') [...] PROBLEM : Because

use GNU parallel in a pipe

╄→гoц情女王★ 提交于 2019-12-24 04:26:09
问题 Running the following command does what I want when reading from a file: parallel --gnu -j2 "echo {} && sleep 5" < myfile.txt I would like to do something similar with a pipe. Note that I used the following page for inspiration for the pipe reader and writer: http://www.linuxjournal.com/content/using-named-pipes-fifos-bash Here is my pipe reader file: #!/bin/bash pipe=/tmp/testpipe trap "rm -f $pipe" EXIT if [[ ! -p $pipe ]]; then mkfifo $pipe fi while true do parallel --gnu -j2 "echo {} &&

Python bash pipe

旧时模样 提交于 2019-12-24 04:18:04
问题 I want to pipe a python script's output to a bash script. What i did so far was i tried to use os.popen() , sys.subprocess() , and tried to give a pipe for an example os.popen('echo "P 1 1 591336 4927369 1 321 " | v.in.ascii -zn out=abcx format=standard --overwrite') but this didn't work, the values "591336" and "4927369" are the variables which comes as the output of the python script. but when I do this or change the values manually by repeating the echo command and the pipe, it works (in

Set output of a command to a variable

时光毁灭记忆、已成空白 提交于 2019-12-24 04:06:10
问题 I want to get the number of files modified before 10 days to a variable. I can get number of files using forfiles /P "D:\files" /S /D -10 | find /c /v "" But when i try to assign it to a variable using FOR it gives error. Command I used in FOR is FOR /F "delims=" %i IN ('forfiles /P "D:\files" /S /D -10 | find /c /v ""') DO set today=%i It actually works fine when I remove | find /c /v "" 回答1: FOR /F "delims=" %i IN ('forfiles /P "D:\files" /S /D -10 ^| find /c /v ""') DO set today=%i in this