Redirecting input to a file - echo the input to screen/file?

Redirecting input to a file - echo the input to screen/file?

Post by ixne » Mon, 21 Apr 2003 17:09:19



Is it possible to have redirected input to a file also echoed to the
screen, or to a file?  For example, if I do something like the following:

$ ./program < input.txt > output.txt 2>&1

The output file shows everything coming out of the program (stdout and
stderr), but doesn't display the input.txt.

I tried adding 0>&1, but no-go (input hosed).

I can also cut and paste the input.txt file right in the shell, but it
doesn't show up for some reason in the shell (Redhat8.0).  Not sure what's
going on, any help appreciated.

 
 
 

Redirecting input to a file - echo the input to screen/file?

Post by Peter T. Breue » Mon, 21 Apr 2003 17:59:04



Quote:> Is it possible to have redirected input to a file also echoed to the
> screen, or to a file?  For example, if I do something like the following:
> $ ./program < input.txt > output.txt 2>&1
> The output file shows everything coming out of the program (stdout and
> stderr), but doesn't display the input.txt.

How would you like it displayed? Before or after? During? Then how
often? One line of input per one line of output?

Quote:> I tried adding 0>&1, but no-go (input hosed).

Answer the question above and you can be advised.

Meanwhile, try doing something less circuitous. Just cat the input.txt
in parallel.

   ( cat & ./program & ; wait;  ) < input.text > output.txt 2>&1

but I honestly think you haven't thought about what you want!

Peter

 
 
 

Redirecting input to a file - echo the input to screen/file?

Post by ixne » Mon, 21 Apr 2003 18:15:29




>> Is it possible to have redirected input to a file also echoed to the
>> screen, or to a file?  For example, if I do something like the
>> following:

>> $ ./program < input.txt > output.txt 2>&1

>> The output file shows everything coming out of the program (stdout and
>> stderr), but doesn't display the input.txt.

> How would you like it displayed? Before or after? During? Then how
> often? One line of input per one line of output?

>> I tried adding 0>&1, but no-go (input hosed).

> Answer the question above and you can be advised.

> Meanwhile, try doing something less circuitous. Just cat the input.txt
> in parallel.

>    ( cat & ./program & ; wait;  ) < input.text > output.txt 2>&1

> but I honestly think you haven't thought about what you want!

What I want is it to display the input text as it is processed.  Maybe
echo is not the right word, but if I type it manually, the input shows up
on the screen, and the output/error prints after linefeeds/enter.
Something like the old telnet sessions, where it would display the input
stream twice; or maybe instead of redirect, direct it to two places at the
same time...

I know this sounds like nonsense, but I simply want to have the input file
show up on the screen as it is processed.  Right now, the input stream
when redirected apparently only shows up in the guts of the ./program.

For example, assume I have a simple program which does:
cout << "Enter Name: "; cin.get(name); cout << "Hello" << name;

I want it to look like this:
Enter Name: Joe
Hello, Joe

With redirect, it looks like this:
Enter Name: Hello, Joe

Thx!

 
 
 

Redirecting input to a file - echo the input to screen/file?

Post by Peter T. Breue » Mon, 21 Apr 2003 18:32:05





>>> Is it possible to have redirected input to a file also echoed to the
>>> screen, or to a file?  For example, if I do something like the
>>> following:

>>> $ ./program < input.txt > output.txt 2>&1

>>> The output file shows everything coming out of the program (stdout and
>>> stderr), but doesn't display the input.txt.

>> How would you like it displayed? Before or after? During? Then how
>> often? One line of input per one line of output?

>>> I tried adding 0>&1, but no-go (input hosed).

>> Answer the question above and you can be advised.

>> Meanwhile, try doing something less circuitous. Just cat the input.txt
>> in parallel.

>>    ( cat & ./program & ; wait;  ) < input.text > output.txt 2>&1

>> but I honestly think you haven't thought about what you want!

> What I want is it to display the input text as it is processed.  Maybe

That's the business of the program. Nobody else knows how much of the
input data it has used in order to produce what output.

Peter

 
 
 

Redirecting input to a file - echo the input to screen/file?

Post by Bill Marcu » Mon, 21 Apr 2003 23:24:04


On Sun, 20 Apr 2003 08:09:19 GMT, ixnei

> Is it possible to have redirected input to a file also echoed to the
> screen, or to a file?  For example, if I do something like the following:

> $ ./program < input.txt > output.txt 2>&1

> The output file shows everything coming out of the program (stdout and
> stderr), but doesn't display the input.txt.

 < input.txt tee | ./program > output.txt 2>&1

--
bill marcum the mushroom-eating laboratory monkey
What kind of monkey are you? http://thesurrealist.co.uk/monkey.cgi

 
 
 

Redirecting input to a file - echo the input to screen/file?

Post by Chris F.A. Johnso » Thu, 24 Apr 2003 12:08:17



> Is it possible to have redirected input to a file also echoed to the
> screen, or to a file?  For example, if I do something like the following:

> $ ./program < input.txt > output.txt 2>&1

> The output file shows everything coming out of the program (stdout and
> stderr), but doesn't display the input.txt.

> I tried adding 0>&1, but no-go (input hosed).

while IFS= read -r line
do
    echo "$line" > /dev/tty
    echo "$line"
done < input.txt | ./program > output.txt 2>&1

    Or, as Peter said, modify .program to display the input (a verbose
    option, for example).

Quote:> I can also cut and paste the input.txt file right in the shell, but it
> doesn't show up for some reason in the shell (Redhat8.0).  Not sure what's
> going on, any help appreciated.

    Unless the program echoes it to the screen, of course it's not
    going to show up.

--
    Chris F.A. Johnson                        http://cfaj.freeshell.org
    ===================================================================
    My code (if any) in this post is copyright 2003, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License

 
 
 

Redirecting input to a file - echo the input to screen/file?

Post by Spamles » Sun, 27 Apr 2003 15:48:32



> Is it possible to have redirected input to a file also echoed to the
> screen, or to a file?  For example, if I do something like the following:

             ^^^^^^^^^^
Echoed to a file?

cat input.txt | tee outfile.1 | program > outfile.2

will save the input.txt file to outfile.1 (which is a little silly -
echoing the input to another file will be a copy of the input file -
not so silly if the input is the output of something else and not
from a file) and pipe the output to program and send the output of
"program input.txt" to outfile.2

Quote:> I can also cut and paste the input.txt file right in the shell, but it
> doesn't show up for some reason in the shell

You cut and pasted the contents to the shell command line?
Each line will be treated as a command.
 
 
 

Redirecting input to a file - echo the input to screen/file?

Post by Spamles » Sun, 27 Apr 2003 16:07:44




>> Is it possible to have redirected input to a file also echoed to the
>> screen, or to a file?  For example, if I do something like the following:
>              ^^^^^^^^^^
> Echoed to a file?

> cat input.txt | tee outfile.1 | program > outfile.2

> will save the input.txt file to outfile.1 (which is a little silly -
> echoing the input to another file will be a copy of the input file -
> not so silly if the input is the output of something else and not
> from a file) and pipe the output to program and send the output of
> "program input.txt" to outfile.2

Of course that tells you how to do it.

1: Two xterm windows open to the same directory.
2: Create a named pipe, say:
   mkfifo mypipe
3: In window 2, give the command
   cat mypipe
4: In window 1, give the command
   cat input.txt | tee mypipe | program

The trick is to send the input file to "mypipe" and then
to the program while in window 1 where you see the program's
action, but the input file (sent to "mypipe" as well) just
pops up in window 2!

(when you're done, you can/should delete mypipe, of course)

 
 
 

1. export `eval echo $"$INPUT"`=${input} not work on Sun Solaris 7

Hi all,

I wrote a function (run with ksh) to get the input and return a string using
the command eval in the function below:

get_input()
{
VAR_INPUT=$1

input=""

while test "${input}" = ""
do
     echo "Input: (q=quit) \c"
     read ${input}
     test "${input}" = "" && continue
     test "${input}" = "q" && exit 1
done

export `eval echo $"$VAR_INPUT"`=${input}

INPUT=""
get_input INPUT

It works with RedHat bash, Unixware 7 and HP-UX 10.20 but it failed with
Solaris 7.

export `eval echo $"${VAR_INPUT}"` = ${input}

it won't get:  export INPUT=${input} with Solaris 7 but
                      export =${input}  so error.

What is the right syntax of eval on Solaris 7 to get the same result on
other platforms or other way more portable to return a string from a
function (ksh/bash)?

Thanks in advance for any help.

DH.

2. Non-destructive Repartitioning an ext2 filesystem

3. standard input instead of input file

4. using /linuxrc

5. File input to variable input

6. getty_ps problems

7. Redirecting Serial port input to a file

8. Trouble to add New Hard Drive to Ultra 1 Solaris 2.6

9. Redirecting two input files to diff..

10. Redirecting Standard Input *TO* a file...

11. Input from keyboard w/o echoing to screen

12. How to redirect input to files given as arguments?

13. Redirect a file to a running program as input?