LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 04-09-2011, 02:25 PM   #1
Xashi
LQ Newbie
 
Registered: Apr 2011
Posts: 3

Rep: Reputation: 0
Open command with pipeline


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"]

Last edited by Xashi; 04-10-2011 at 01:48 AM.
 
Old 04-09-2011, 02:28 PM   #2
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
Hello and welcome to LQ!

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....

Cheers,

Josh

PS - By the way, the pipe "|" directs output to a pipe - see this following link for details, as I have a hard time describing certain things... https://secure.wikimedia.org/wikiped...ine_%28Unix%29
 
Old 04-09-2011, 02:41 PM   #3
jmc1987
Member
 
Registered: Sep 2009
Location: Oklahoma
Distribution: Debian, CentOS, windows 7/10
Posts: 893

Rep: Reputation: 119Reputation: 119
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.

Last edited by jmc1987; 04-09-2011 at 02:43 PM.
 
Old 04-10-2011, 01:49 AM   #4
Xashi
LQ Newbie
 
Registered: Apr 2011
Posts: 3

Original Poster
Rep: Reputation: 0
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.

Last edited by Xashi; 04-10-2011 at 01:59 AM.
 
Old 04-10-2011, 04:14 PM   #5
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,776

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
First case:
set fd1 [open "simpleinput" "r"] ;
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
 
1 members found this post helpful.
Old 04-11-2011, 12:18 AM   #6
Xashi
LQ Newbie
 
Registered: Apr 2011
Posts: 3

Original Poster
Rep: Reputation: 0
Thanx rknichols for a comprehensive and detailed explanation. I got it now
 
Old 04-12-2011, 08:08 AM   #7
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,776

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
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.
 
Old 04-12-2011, 07:48 PM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,358

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
In the 4th case, the pipe comes after the executable name surely?
 
Old 04-12-2011, 11:30 PM   #9
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,776

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Quote:
Originally Posted by chrism01 View Post
In the 4th case, the pipe comes after the executable name surely?
No. RTFM.
 
Old 04-13-2011, 05:36 AM   #10
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
Quote:
Originally Posted by rknichols View Post
No. RTFM.
Wow, dude.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Using variable to store command lines in a pipeline? zizou86 Programming 6 01-29-2010 10:20 AM
how to pipeline when the file requires two command line args???? lemon09 Programming 4 01-19-2010 09:24 PM
noob Pipeline help. promero Programming 8 09-11-2005 03:42 PM
pipeline using rm verstapp Linux - General 3 03-08-2004 11:33 PM
Pipeline implementation in C jiahe Programming 1 02-02-2003 05:23 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:05 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration