Operating System - HP-UX
1830216 Members
2012 Online
109999 Solutions
New Discussion

How to copy stdin to stdout within a ksh script

 
SOLVED
Go to solution
Gary Cooper_1
Esteemed Contributor

How to copy stdin to stdout within a ksh script

I'm pulling my hair out (what little is left). I just can't work out how to do this, although I'm sure it's really simple.

Starting with:
> progA | progB

What I want to do is run a script which will do some analysis on the output of progA, but will also pass progA's output to progB unaltered, so that my command look like:

> progA | myprog | progB

BTW, the output of progA is not in a text format.

Thanks,

Gary
7 REPLIES 7
Thierry Poels_1
Honored Contributor

Re: How to copy stdin to stdout within a ksh script

hi,

maybe "tee" can help you.

progA | tee -a myfile | progB
cat myfile | myprog

regards,
Thierry.
All unix flavours are exactly the same . . . . . . . . . . for end users anyway.
Thierry Poels_1
Honored Contributor

Re: How to copy stdin to stdout within a ksh script

maybe even beter (preserves the processing sequence):

progA > myfile
cat myfile | myprog
cat myfile | progB

regards,
Thierry.
All unix flavours are exactly the same . . . . . . . . . . for end users anyway.
Gary Cooper_1
Esteemed Contributor

Re: How to copy stdin to stdout within a ksh script

Hi Thierry,

OK, let me go into a bit more detail...

I have an application which has a configuration file and in that configuration file, there is a variable called printCommand. Print command is currently:

xpr -device dj1200 | lp -oraw -dlp4650c1

When a print is kicked off within the application it prints a dump of the window by executing:

xwd | xpr -device dj1200 | lp -oraw -dlp4650c1

I.e. all I have to work with is the output from xwd and the ability to modify printCommand.

Now, for one class of users, the print fails and by inserting 'tee's I've found out that it's xpr where it's going wrong.

What I want to do is something along the lines of:

xwd | dump_environment_variables | xpr -device dj1200 | lp -oraw -dlp4650c1

for both sets of users so that I can see what's different in their environments.

I hope that clarifies my problem.

Thanks,

Gary
Rodney Hills
Honored Contributor
Solution

Re: How to copy stdin to stdout within a ksh script

How about-

xwd | ( dump_env.sh ; xpr ...)

If you use semicolon, dump_env.sh will run and as long as you don't use STDIN and STDOUT, then xpr can pick up the output from xwd.

HTH

-- Rod Hills
There be dragons...
Gary Cooper_1
Esteemed Contributor

Re: How to copy stdin to stdout within a ksh script

Thanks for the response Rodney,

Can you explain how the round brackets figure in your example?

Thanks,

Gary
Rodney Hills
Honored Contributor

Re: How to copy stdin to stdout within a ksh script

I wasn't sure if the () were needed. They group the set of commands in a seperate environment. I wanted to be sure that STDIN from the previous pipe got assigned to both commands in the parenthesis. They may not be needed. Try it both ways.

--Rod Hills
There be dragons...
Gary Cooper_1
Esteemed Contributor

Re: How to copy stdin to stdout within a ksh script

Thanks for the solution Rod.

It worked a treat.

..and yes, the braces were needed!

Regards,

Gary