How to call UNIX sort command on data in pipe

2015-01-07T08:37:15

I am creating a C program and with it I am setting up a pipe between separately forked process for interprocess communication.

The first process has written the data I need into the pipe. However, with the second process reading from the pipe, I am trying to exec the process to become the UNIX sort command. I want to somehow call sort on the data in the pipe.

How can I call sort on a pipe? On the commandline, I can sort by supplying the filename to sort as a commandline argument e.g. "sort -r MyFileToSort". I know that pipes are essentially considered files, but they are only described by their file descriptor, and as far as I know, sort won't know what to do with a fd.

Thanks for any help/feedback

Copyright License:
Author:「pleaver」,Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.
Link to:https://stackoverflow.com/questions/27809692/how-to-call-unix-sort-command-on-data-in-pipe

About “How to call UNIX sort command on data in pipe” questions

I am creating a C program and with it I am setting up a pipe between separately forked process for interprocess communication. The first process has written the data I need into the pipe. However,
I have an exercise where I should read an infile text and pass them with Unix pipes (fork() etc) and print them to the screen for starters.I ' ve accomplished that but now I need to sort the charac...
Right now I'm using another text file to store the result of one UNIX command and then using that file to run another command, like so: tr -d "[,|.]" < text > temporary.txt tr "[A-Z]" "[a-z]...
I have a command sort -n +1 -2 -o /tmp/ord_id in a C file that i call using system, which is pretty bad. How would i go about creating a quicksort function to complete the same tasks that the unix
I have a command line utility from a third party (it's big and written in Java) that I've been using to help me process some data. This utility expects information in a line delimited file and then
zcat big.txt.gz | split -l 1000000 - prefix where big.txt.gz is 150 GB, say it has ~1 billion lines. In this case, does the unix pipe "stream" the data into split, or is the zcat operation
The UNIX sort command can sort a very large file like this: sort large_file How is the sort algorithm implemented? How come it does not cause excessive consumption of memory?
The UNIX sort command can sort a very large file like this: sort large_file How is the sort algorithm implemented? How come it does not cause excessive consumption of memory?
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 writ...
I have 2 questions 1) how do I i invoke a unix shell from a java.runtime library to run a command like this Process p = Runtime.getRuntime().exec(commands); cat alias > bias 2) How can I read...

Copyright License:Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.