Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

How to interactive with programs while in awk mode
say I have two programs in one directory

prg1
prg2

both program has some questions to ask, such as what's the directory,
yes or no and etc, and all different.

I tried
ls -l | awk '{print $11 }' | sh

I hope prg1 and prg2 will run consequentially, but actually no, prg2's
name has been treated as user's answer for "yes/no" and "directory".

Any suggestion to force prg1 get parameter from keyboard instead of
pipe?

Thanks a lot

Report this thread to moderator Post Follow-up to this message
Old Post
BlueDolphin
09-17-04 01:10 AM


Re: How to interactive with programs while in awk mode
In article <343e3ab2.0409161018.6ae041f3@posting.google.com>,
BlueDolphin <aliceliu106@yahoo.com> wrote:
% say I have two programs in one directory
%
% prg1
% prg2

[...]
%
% I tried
% ls -l | awk '{print $11 }' | sh

Think about why you're using ls here. Then think about why you're
using the -l switch to ls when all you want is the file name. Why
not use

ls | awk '{ print $1 }' | sh

? Of course, that simplifies to

ls | sh

albeit going off-topic in the process, and without solving your
problem.

One way to get the effect you crave is to run ls from within
awk, read its output using getline, and use the system command
to execute the commands:

awk 'BEGIN {
while ("ls" | getline)
system($0)
close("ls")
}'

If you really need the programs to run in the same shell, you can build
a command-line first

awk 'BEGIN {
cmd = ""
while ("ls" | getline)
cmd = cmd $0 ";"
close("ls")
system(cmd)
}'

Normally, I wouldn't use awk for this, though:


for a in prg*
do
$a
done
--

Patrick TJ McPhee
East York  Canada
ptjm@interlog.com

Report this thread to moderator Post Follow-up to this message
Old Post
Patrick TJ McPhee
09-17-04 08:56 AM


Re: How to interactive with programs while in awk mode
On 17 Sep 2004 00:22:38 GMT in comp.lang.awk, ptjm@interlog.com
(Patrick TJ McPhee) wrote:

>Normally, I wouldn't use awk for this, though:
>
>for a in prg*
>do
if [ -x $a ]
then
>    $a
fi
>done

--
Thanks. Take care, Brian Inglis 	Calgary, Alberta, Canada

Brian.Inglis@CSi.com  	(Brian[dot]Inglis{at}SystematicSW[dot]a
b[dot]ca)
fake address		use address above to reply

Report this thread to moderator Post Follow-up to this message
Old Post
Brian Inglis
09-28-04 08:55 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

AWK archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 05:13 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.