LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 06-07-2004, 06:27 AM   #1
funkymunky
Member
 
Registered: Jun 2003
Location: Austin, Texas
Distribution: Fedora Core 8, 32-bit
Posts: 126

Rep: Reputation: 15
Unhappy BASH scripting: confused about redirection & file descriptors


hello!

i horribly confused with this redirection business..iv tried hard, but the nail refuses to go into the wall..

i am working with two virtual terminals, /dev/pts/0 and /dev/pts/1
i do this:

echo "hello" >/dev/pts/0

from pts/1, and a "hello" appears on pts/0 as expected..what i want is that whatever appears on pts/0 should go into a file, from where it can be read..
i tried this

exec 1<"/dev/pts/0" 1>&"tempfile"

is this wrong? im a to shell scripting, so plz accomodate

also, how do file descriptors work? i mean, when a file descriptor is associated with a file, what exactly does it mean?

in the place of whats typed above, is this correct:

4<>"tempfile"
exec 4<"/dev/pts/0"
HELP !!



(actually, what im trying to do is that i hav a small script to send a command to /pts/0 from /pts/2, and then on the basis of the output received. check whether the command was succesful..all through the script.)
 
Old 06-07-2004, 07:47 AM   #2
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 96
Hi.

There's a utility called 'tee' which allows you to send output to several files, and std out. See 'man tee' for details. I don't think it will make a lot of difference, as I can't get echoed commands to 'press return' and therefore execute the command.

There is a way around this, though. I don't even know if this is what you're looking for, but here goes.

Do the following:
Open two xterms (konsole, or whatever). In one of them, do:
$mkfifo fifo1
$touch fifoout
$chmod +x fifoout

Now, type in the following into the terminal you want to recieve commands:
$while true; do cat fifo1 > fifoout; ./fifoout | tee output; done;
and hit return. You shouldn't get any output from that console at this point - it should appear to have 'crashed'. This is good. Because it's a fifo pipe, and not a file that's being cat'ed, it doesn't use any processor time - it just waits for a command.

In the other terminal, echo your commands to the fifo1 file, e.g.:
$echo "who" > fifo1
The result of 'who' should appear in the other console and in the file 'output' (the output file gets wiped before each command, so it will only contain the output of the last command, which may, or may not be useful). Should you need a listing of all the outputs of all the commands, then put 'while true; do cat fifo1 > fifoout; ./fifoout; done' in a script and run it with './name_of_script | tee output', instead of running '$while true; do cat fifo1 > fifoout; ./fifoout | tee output; done;' directly in the recieving console as shown above.

As I said, it may not be what you're looking for, and there's probably a really simple solution that I've missed, but it does work.

Dave

Last edited by ilikejam; 06-07-2004 at 07:54 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
BASH scripting I/O redirection error blinux1 Programming 13 03-18-2008 08:21 PM
Bash Scripting Empty file john8675309 Linux - Software 2 08-08-2007 04:05 PM
Bash scripting and && operator Dark_Helmet Programming 16 09-18-2005 09:57 PM
bash scripting read from file cadj Programming 2 02-29-2004 10:42 PM
bash shell scripting - && and || gui10 Programming 10 12-15-2001 03:37 PM


All times are GMT -5. The time now is 05:09 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration