yet an other.

What do you want to see in Armagetron soon? Any new feature ideas? Let's ponder these ground breaking ideas...
User avatar
Jonathan
A Brave Victim
Posts: 3392
Joined: Thu Feb 03, 2005 12:50 am
Location: Not really lurking anymore

Post by Jonathan »

Code: Select all

x | y
This runs x and y and sends the output of x to the input of y. Here x is Armagetron, and y is tee. tee is a program that echoes whatever is sent as input but also writes it to a file (or more of them, at least on OS X). It lets you save the output and look at it at the same time (another option is command > file, but then the output ONLY goes to that file).
ˌɑrməˈɡɛˌtrɑn

User avatar
Lucifer
Project Developer & Local Moonshiner
Posts: 8610
Joined: Sun Aug 15, 2004 3:32 pm
Location: Republic of Texas
Contact:

Post by Lucifer »

You can pick up terminal work on-the-fly for the most part. :)

What Jonathan seems to have managed not to say is that the | is a pipe. It's also commonly called a pipe character, and that's not coincidence.

UNIX and clones have the concept of something called a pipe. A pipe is a pipe, really, just like the pipes in your sink (hence the name). It lets you connect any arbitrary program to any other arbitrary program. They come in two flavors, but I only know what one of them is called. That's named pipes. A named pipe exists on disk and looks like a file to any program that opens it, but doesn't behave exactly like a file (there's no end-of-file marker in a named pipe). The type of pipe created here, in z-man's command, is the other kind. It's ad-hoc, kind of like an improvised pipe. The kernel creates it, hooks the two programs up to it, then runs them, then destroys the pipe. Named pipes have to be deleted by hand, typically.

When you connect a program to a pipe, the kernel doesn't actually start the program. For example, this sequence of commands is always fun:

mkfifo someyoungguy
cat someyoungguy

If you put that in your terminal, nothing happens, right? That's because the pipe only has one program connected to it, and that program is "cat", which just reads the pipe. At this point, the kernel hasn't even started cat, all it's done is note that cat will be started when this pipe has something connected to the other end.

Go into a second terminal and do this:

cat > someyoungguy

Now start typing in that second terminal. FOr best effect, move both terminal windows and resize them so that you can see the first terminal while you're typing into the second.

To finish, press ctrl-D. That gives cat an end-of-file marker and closes it, which kills the whole sequence.

Pipes are the original means by which programs communicated with each other, and were a crucial development in the early days of UNIX. In fact, Kerrigan (I think) has an essay that's actually an extract of a book where he talks about the day the pipe was invented in the late 60s as a defining moment in the development of UNIX. Pipes are the reason, in my opinion, that Windows will always be inferior to UNIX and its clones. Windows doesn't have pipes.

so, this is the long version of Jonathan's explanation. :)
Image

Be the devil's own, Lucifer's my name.
- Iron Maiden

QUARG
Round Winner
Posts: 223
Joined: Thu Sep 14, 2006 2:38 pm
Location: montreal

Post by QUARG »

Ty for the explination Lucifer. I tried what you suggested with the cat command, didnt do anything. I probably got it wrong.
If i understand this right pipe is like an operator in the telephone system. Sombody makes the request to speak with an other person. pipe makes the connection.

User avatar
philippeqc
Long Poster - Project Developer - Sage
Posts: 1526
Joined: Mon Jul 12, 2004 8:55 am
Location: Stockholm
Contact:

Post by philippeqc »

QUARG wrote:O.O it works!!!
God i need to learn treminal language. I understand the structure of the command now that you clarified it. Im quite sure what the | tee is.
Ill have to put terminal 101 off till i get my other projects done.:)
Thankyou for your help guys.
tee will take data from stdin (what come out from the previous command, send to itself through "|"), and write it to a file AND send it out to stdout again, allowing you both to log it and to manipulate it on the fly.

Shells are what you refer to as terminal. Each shell have it own syntax and thus scripting "language". Not knowing what platform you are using (I guess it is a mac), nor which shells are available to you (Last time I used a mac, they hadn't yet started with the iFruity ones), I'd say google for any bash tutorial. By the time you figure out your own terminal, the little you will have learn should still be applicable to any shell.

Good luck

7ph
Canis meus id comedit.

User avatar
Jonathan
A Brave Victim
Posts: 3392
Joined: Thu Feb 03, 2005 12:50 am
Location: Not really lurking anymore

Post by Jonathan »

That's not entirely correct. The shell is what gives you your prompt and lets you start other programs, and possibly a lot more. The terminal is just what manages user IO (in the past it used to be a physical device, which leads to the term terminal emulator today). As if a desktop environment and a monitor are the same thing.
ˌɑrməˈɡɛˌtrɑn

User avatar
Lucifer
Project Developer & Local Moonshiner
Posts: 8610
Joined: Sun Aug 15, 2004 3:32 pm
Location: Republic of Texas
Contact:

Post by Lucifer »

QUARG wrote:Ty for the explination Lucifer. I tried what you suggested with the cat command, didnt do anything. I probably got it wrong.
If i understand this right pipe is like an operator in the telephone system. Sombody makes the request to speak with an other person. pipe makes the connection.
Your understanding is good. :) And the conversation in your comparison can't begin until both people are connected.

I'd need to see what you tried, but you do have to press return on the second terminal before you'll see something in the first. And there's an implicit assumption that both terminals open to the same working directory. If not, then you need paths to where you put the pipe (also called fifos when created and used in this manner, fifo just means "first in first out").
Image

Be the devil's own, Lucifer's my name.
- Iron Maiden

QUARG
Round Winner
Posts: 223
Joined: Thu Sep 14, 2006 2:38 pm
Location: montreal

Post by QUARG »

I input the command lines you suggested.Into the first treminal window.

Code: Select all

modemcable004:~ marclizotte$ cat someyougguy
Into the second i input the second command that you suggested.

Code: Select all

modemcable004:~ marclizotte$ cat > someyoungguy
i saw no reaction when i hit enter in either window. Was i supposed to cd into an other directory before hand? Here i am in my main user directory.

User avatar
Jonathan
A Brave Victim
Posts: 3392
Joined: Thu Feb 03, 2005 12:50 am
Location: Not really lurking anymore

Post by Jonathan »

You are supposed to type something in the second window.
ˌɑrməˈɡɛˌtrɑn

User avatar
Lucifer
Project Developer & Local Moonshiner
Posts: 8610
Joined: Sun Aug 15, 2004 3:32 pm
Location: Republic of Texas
Contact:

Post by Lucifer »

Yeah, what JOnathan said. There's also a typo in the first command in your post, the name of the pipe is wrong. :)

What's supposed to happen is that what you type in the second terminal should appear in the first. Real basic, but the program that does it, "cat", is a program written to concatenate text files, and that's all it does. But using a pipe makes it into a really basic chat program. ;)
Image

Be the devil's own, Lucifer's my name.
- Iron Maiden

k
Random Identifier & Project Developer
Posts: 345
Joined: Wed Feb 25, 2004 12:54 am
Location: Northern California, USA

Post by k »

Lucifer wrote:Pipes are the reason, in my opinion, that Windows will always be inferior to UNIX and its clones. Windows doesn't have pipes.
Windows has pipes. It has the command line pipes inherited from DOS:

Code: Select all

C:> DIR | SORT | MORE
and named pipes: http://en.wikipedia.org/wiki/Named_pipe

User avatar
Lucifer
Project Developer & Local Moonshiner
Posts: 8610
Joined: Sun Aug 15, 2004 3:32 pm
Location: Republic of Texas
Contact:

Post by Lucifer »

Uh, that's not exactly a pipe. More like it's something that somewhat resembles a pipe and is called a pipe, but is waaaay inferior.

I suppose you could write a commandline app to provide the mkfifo feature, but can you redirect input/output to it after doing so?

In Unix, those pipes you stick on the command line and the pipes you create with mkfifo are identical. This windows thing looks to be quite different.
Image

Be the devil's own, Lucifer's my name.
- Iron Maiden

k
Random Identifier & Project Developer
Posts: 345
Joined: Wed Feb 25, 2004 12:54 am
Location: Northern California, USA

Post by k »

Lucifer wrote:A pipe is a pipe, really, just like the pipes in your sink (hence the name). It lets you connect any arbitrary program to any other arbitrary program.
By your definition Windows has pipes. :wink:

User avatar
Lucifer
Project Developer & Local Moonshiner
Posts: 8610
Joined: Sun Aug 15, 2004 3:32 pm
Location: Republic of Texas
Contact:

Post by Lucifer »

Ah, see, don't confused defintions. :) I gave a guy an explanation that I hoped he'd be able to use to learn about pipes on his computer, it's not intended to be rigorous.
Image

Be the devil's own, Lucifer's my name.
- Iron Maiden

QUARG
Round Winner
Posts: 223
Joined: Thu Sep 14, 2006 2:38 pm
Location: montreal

Post by QUARG »

back to the chat log. is there a way to save it in a windows machine?

Post Reply