piping

Bash piping in OSX prompts command not found, sometimes

僤鯓⒐⒋嵵緔 提交于 2019-11-28 20:45:54
In the OSX terminal : du -h | sort -nr -bash: sort: command not found which sort /usr/bin/sort The weird thing is: I tried reproducing the error and it seems to be totally random. My PATH echoed: /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/local/git/bin:/usr/texbin:/Users/sytycs/.rvm/bin This only occurs when piping and happens with grep , more , less etc. Any idea what is causing this? That space is not a space. Erase and replace it. Michael Trojanek This likely happens because you use a keyboard layout with a non-US layout (happened to me too). On German layouts, the pipe

Pipe implementation

為{幸葍}努か 提交于 2019-11-28 09:20:19
I am trying to implement a linux shell that supports piping. I have already done simple commands, commands running in background, redirections, but piping is still missing. I have already read about it and seen some snippets of code, but still haven't been able to sort out a working solution. What I have so far: int fd[2]; pipe(fd); pid_t pid = fork(); if (pid == -1) return -1; if (pid == 0) { close(fd[1]); //close write to pipe, in child execlp("cat", "cat", "names.txt", NULL); } else { close(fd[0]); //close read from pipe, in parent execlp("sort", "sort", NULL); } I am a novice programmer,

Python piping on Windows: Why does this not work?

半城伤御伤魂 提交于 2019-11-28 08:34:35
I'm trying something like this Output.py print "Hello" Input.py greeting = raw_input("Give me the greeting. ") print "The greeting is:", greeting At the cmd line Output.py | Input.py But it returns an EOFError . Can someone tell me what I am doing wrong? Thanks for your help. EDIT Patrick Harrington solution works but I don't know why... I tested this on my Windows machine and it works if you specify the Python exe: C:\>C:\Python25\python.exe output.py | C:\Python25\python.exe input.py Give me the greeting. The greeting is: hello But I get an EOFError also if running the commands directly as:

CMD: piping ECHO to SET/ expanding variables in variables

纵饮孤独 提交于 2019-11-28 02:22:59
%x:~12,3% Returns 3 characters starting at the 12:th character in x variable. What I have been trying to accomplish is using variables instead of 12 and 3 . Let's say y=12 and z=3 . Then, you can't use %x:~%y%,%z%% , because CMD will think %x:~% is a variable. What you can do is set var=%%x:~%y%,%z%%% . This will expand the inside variables y and z , but not x , so that the value of var is %x:~12,3% . The remaining task at hand now is to finally expand %x:~12,3% . I have been trying to append echo in the beginning so that var=echo %x:~12,3% . If at the commandline or in a batch file you now

Piping and Redirection

江枫思渺然 提交于 2019-11-27 18:33:39
What is exact difference between Piping and Redirection ? Where should we use piping and where should we use redirection ? How they internally work ? sirgeorge Redirection is (mostly) for files (you redirect streams to/from files). Piping is for processes: you pipe (redirect) streams from one process to another. Essentially what you really do is "connect" one standard stream (usually stdout ) of one process to standard stream of another process (usually stdin ) via pipe. Pipes have also the synchronization "side effect" : they block one process (on reading) when the other has nothing to write

putting a remote file into hadoop without copying it to local disk

久未见 提交于 2019-11-27 17:27:20
I am writing a shell script to put data into hadoop as soon as they are generated. I can ssh to my master node, copy the files to a folder over there and then put them into hadoop. I am looking for a shell command to get rid of copying the file to the local disk on master node. to better explain what I need, here below you can find what I have so far: 1) copy the file to the master node's local disk: scp test.txt username@masternode:/folderName/ I have already setup SSH connection using keys. So no password is needed to do this. 2) I can use ssh to remotely execute the hadoop put command: ssh

Bash piping in OSX prompts command not found, sometimes

谁说胖子不能爱 提交于 2019-11-27 12:27:58
问题 In the OSX terminal : du -h | sort -nr -bash: sort: command not found which sort /usr/bin/sort The weird thing is: I tried reproducing the error and it seems to be totally random. My PATH echoed: /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/local/git/bin:/usr/texbin:/Users/sytycs/.rvm/bin This only occurs when piping and happens with grep , more , less etc. Any idea what is causing this? 回答1: That space is not a space. Erase and replace it. 回答2: This likely happens because

Using fseek with a file pointer that points to stdin

倾然丶 夕夏残阳落幕 提交于 2019-11-27 05:25:51
Depending on command-line arguments, I'm setting a file pointer to point either towards a specified file or stdin (for the purpose of piping). I then pass this pointer around to a number of different functions to read from the file. Here is the function for getting the file pointer: FILE *getFile(int argc, char *argv[]) { FILE *myFile = NULL; if (argc == 2) { myFile = fopen(argv[1], "r"); if (myFile == NULL) fprintf(stderr, "File \"%s\" not found\n", argv[1]); } else myFile = stdin; return myFile; } When it's pointing to stdin, fseek does not seem to work. By that, I mean I use it and then use

Making C code plot a graph automatically

北城以北 提交于 2019-11-27 03:25:50
I have written a program which writes a list of data to a '.dat' file with the intention of then plotting it separately using gnuplot. Is there a way of making my code plot it automatically? My output is of the form: x-coord analytic approximation x-coord analytic approximation x-coord analytic approximation x-coord analytic approximation x-coord analytic approximation .... Ideally, when I run the code the graph would also be printed with an x-label, y-label and title (which could be changed from my C code). Many thanks. I came across this while searching for something else regarding gnuplot.

Piping both stdout and stderr in bash?

老子叫甜甜 提交于 2019-11-27 03:14:19
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 stream). Note : this question is asking about piping, not redirecting - so it is not a duplicate of the