Welcome to Coding : Sécurité Programmation Réseaux

Search   in  

 Create an Account Home | Submit News Your Account Content | Topics | Top 10  


Accueil
· Home
· Listing des Articles
· Top 10
· Repository des Exploits

Les sujets / parties
· C / C ++
· Visual Basic
· Asm
· Reseaux
· Java
· Securite
· Divers

Utile
· Listing des Articles

· Telecharger
· Le Forum
· Liens
· Proposer un article

Top20 des Downloads
· 1: Etude des reseaux generalites et protocoles
· 2: Cheval de troie en VB avec sources
· 3: Netcat 1.1
· 4: Keylogger
· 5: Etudes des reseaux hauts debits architectures et protocoles
· 6: Ecoute de port
· 7: Etude du Smart Spoofing
· 8: Win Packet Capture Utils
· 9: Tutorial on Traffic Interception on Switched Lan using ARP spoofing
· 10: Cours de C

User Info
Welcome, Anonymous
Nickname
Password
(Register)
Membership:
Latest: trapcodien
New Today: 1
New Yesterday: 0
Overall: 2207

People Online:
Visitors: 40
Members: 1
Total: 41

Online Now:
01: trapcodien

  
Coding : Sécurité Programmation Réseaux: Forums

Coding :: View topic - How to accept input from stdin?
 Forum FAQForum FAQ   SearchSearch   UsergroupsUsergroups   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to accept input from stdin?

 
Post new topic   Reply to topic    Coding Forum Index -> Scripting
View previous topic :: View next topic  
Author Message
PengYu.UT@gmail.com
Guest





PostPosted: Fri Jul 04, 2008 8:10 am    Post subject: How to accept input from stdin? Reply with quote

Hi,

I try to make a wrapper around an existing program, which would behave
exactly the same as the original one. But my following attempt was
failed. Would you pleaes let me know what is the correct way?

Thanks,
Peng

$cat ./my_tee.sh
#!/bin/bash

read

echo $REPLY | tee $*
$ cat abc
a
b
c
$ cat abc | ./my_tee.sh efg
a
Back to top
pk
Guest





PostPosted: Fri Jul 04, 2008 8:10 am    Post subject: Re: How to accept input from stdin? Reply with quote

On Thursday 3 July 2008 20:24, PengYu.UT@gmail.com wrote:

Quote:
Hi,

I try to make a wrapper around an existing program, which would behave
exactly the same as the original one. But my following attempt was
failed. Would you pleaes let me know what is the correct way?

Thanks,
Peng

$cat ./my_tee.sh
#!/bin/bash

read

echo $REPLY | tee $*
$ cat abc
a
b
c
$ cat abc | ./my_tee.sh efg
a

What about

cat abc | efg

or, better

efg < abc

or, better yet, explain what you're trying to do?

--
All the commands are tested with bash and GNU tools, so they may use
nonstandard features. I try to mention when something is nonstandard (if
I'm aware of that), but I may miss something. Corrections are welcome.
Back to top
Bill Marcum
Guest





PostPosted: Fri Jul 04, 2008 8:10 am    Post subject: Re: How to accept input from stdin? Reply with quote

On 2008-07-03, PengYu.UT@gmail.com <PengYu.UT@gmail.com> wrote:
Quote:


Hi,

I try to make a wrapper around an existing program, which would behave
exactly the same as the original one. But my following attempt was
failed. Would you pleaes let me know what is the correct way?

Thanks,
Peng

$cat ./my_tee.sh
#!/bin/bash

read

echo $REPLY | tee $*
$ cat abc
a
b
c
$ cat abc | ./my_tee.sh efg
a

IFS=
while read; do
echo "$REPLY"
done |tee "$@"

or

IFS=
while read; do
echo "$REPLY" | tee -a "$@"
done
Back to top
Chris F.A. Johnson
Guest





PostPosted: Fri Jul 04, 2008 8:10 am    Post subject: Re: How to accept input from stdin? Reply with quote

On 2008-07-03, PengYu.UT@gmail.com wrote:
Quote:
Hi,

I try to make a wrapper around an existing program, which would behave
exactly the same as the original one. But my following attempt was
failed. Would you pleaes let me know what is the correct way?

That depends on what you want to do.

Quote:
$cat ./my_tee.sh
#!/bin/bash

read

echo $REPLY | tee $*
$ cat abc
a
b
c
$ cat abc | ./my_tee.sh efg
a

How about:

tee "$@" | do_whatever

Replace 'do_whatever' with whatever you want to do to the input.

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell/>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
Back to top
OldSchool
Guest





PostPosted: Fri Jul 04, 2008 8:10 am    Post subject: Re: How to accept input from stdin? Reply with quote

On Jul 3, 2:24 pm, "PengYu...@gmail.com" <PengYu...@gmail.com> wrote:
Quote:
Hi,

I try to make a wrapper around an existing program, which would behave
exactly the same as the original one. But my following attempt was
failed. Would you pleaes let me know what is the correct way?

Thanks,
Peng

$cat ./my_tee.sh
#!/bin/bash

read

echo $REPLY | tee $*
$ cat abc
a
b
c
$ cat abc | ./my_tee.sh efg
a

most shells support "here-docs" so something like:

./my_tee.sh efg <<-ENDIT
a
b
c
ENDIT

ought to work, or look at "expect".
Back to top
PengYu.UT@gmail.com
Guest





PostPosted: Fri Jul 04, 2008 8:10 am    Post subject: Re: How to accept input from stdin? Reply with quote

On Jul 3, 1:31 pm, pk <p...@pk.invalid> wrote:
Quote:
On Thursday 3 July 2008 20:24, PengYu...@gmail.com wrote:



Hi,

I try to make a wrapper around an existing program, which would behave
exactly the same as the original one. But my following attempt was
failed. Would you pleaes let me know what is the correct way?

Thanks,
Peng

$cat ./my_tee.sh
#!/bin/bash

read

echo $REPLY | tee $*
$ cat abc
a
b
c
$ cat abc | ./my_tee.sh efg
a

What about

cat abc | efg

or, better

efg < abc

or, better yet, explain what you're trying to do?

I'm trying to mimic an existing command. Of course, in practice, the
new command is different from the old one, otherwise, this is no
point. As a simplification, in my example, the new command (my_tee.sh)
shall do the same thing as the old command (tee).

The point is that I want the new one accept exactly the same set of
command line arguments as well as the stdin as the old one.

Thanks,
Peng
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Coding Forum Index -> Scripting All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB © 2001, 2005 phpBB Group
PHP-Nuke Copyright © 2005 by Francisco Burzi. This is free software, and you may redistribute it under the GPL. PHP-Nuke comes with absolutely no warranty, for details, see the license.
Page Generation: 0.38 Seconds