Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
What is the effect of pipe symbol in the second statement shown below? How does it differ from first one?
set nt [open "file" "r"]
set nt [open "|file" "r"]
Where are you running or setting this command from? From the linux command line, or within another program? The more details you give us, the better....
The pipe command is pretty much allows you to issue a command and filter it through another. Example say you want to list all services That are set to start on boot you would do this to get the list
# chkconfig --list
This will list all services
Now if you wanted to see what servers are on and thats all you want you would want to filter the list through something like grep.
Example
# chkconfig --list |grep on
Here is another example.
If you did
$ls /etc
You would get all files listed. But say you wanted to list them from top to bottom and scroll down them. Then you would filter it though another program though the pipe. Such as
$ls /etc |less
But im not sure exactly what info you want to you need to provide more details.
Basically it is a piece of Tcl code. I was learning how to run Unix programs with Tcl scripts using open and exec commmands.The open command returns a file descriptor which in this example, is assigned to variable nt.I have learned that "If the first character of fileName is not | then the open command opens a file: fileName gives the name of the file to open. If the first character of fileName is “|” then the remaining characters of fileName are treated as a list of arguments that describe a command pipeline to invoke, in the same style as the arguments for exec. In this case, the channel identifier returned by open may be used to write to the command's input pipe or read from its output pipe, depending on the value of access. If write-only access is used (e.g. access is w), then standard output for the pipeline is directed to the current standard output unless overridden by the command. If read-only access is used (e.g. access is r), standard input for the pipeline is taken from the current standard input unless overridden by the command."
What I dont understand is that what is meant by Command pipeline and channel identifier in above explanation. Also another example
set fd1 [open "simpleinput" "r"] ;# open the file for reading
set fd5 [open "|simple1" "r"] ;# Read the stdout of simple1 as fd5
set fd2 [open "reldirect/simpleoutput" "w"] ;# open the file for writing
set fd6 [open "|simple2" "w"] ;# Writes to fd6 are read by simple2 on its stdin
How does second statement differ from first one in each pair.
simpleinput is a file in the current working directory, and you are creating a tcl channel identifier fd1, which can now be used to read from that file.
2nd case:
set fd5 [open "|simple1" "r"] ;
simple1 is a program or script that will be executed, and the standard output from that program (the stream that would be sent to the terminal if you invoked the program directly from the command line) can now be read from tcl channel identifier fd5.
3rd case:
set fd2 [open "reldirect/simpleoutput" "w"] ;
simpleoutput is a file in directory reldirect below the current working directory, and you are opening that file (which will be created if it does not already exist) to receive any data that you send to tcl channel identifier fd2.
4th case:
set fd6 [open "|simple2" "w"] ;
simple2 is again a program or script that will be executed, and whatever you write to tcl channel identifier fd6 will be sent to that program's standard input.
Last edited by rknichols; 04-12-2011 at 08:06 AM.
Reason: correct confusion of tcl channel identifiers with file descriptor numbers
Actually there were multiple errors in what I wrote. fd1, fd2, etc., are arbitrary tcl channel identifier names that bear enough resemblance to file descriptor numbers to get me confused. To make matters worse, file descriptor numbers start at 0 for "stdin" and 1 for "stdout", so my description of the standardized file descriptor numbers was flat out wrong. What I originally posted was probably close enough to get you on the right path, but I've made corrections to avoid confusing anyone else who comes across this.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.