CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Automatically Answering Application Questions Using Perl

 



Zissou
New User

Oct 27, 2008, 12:33 PM

Post #1 of 8 (1134 views)
Automatically Answering Application Questions Using Perl Can't Post

Hello,

I'm new to perl and looking to do something advanced. I would greatly appriciate any time and help that any forum members can donate.

My Issue:

I have been tasked to automate a vulnerability scan process for unix machines. The problem I have ran into is that the majority of the scripts require user input. For example,

if i run ./DBupdate I'm almost immdiately prompted with the question "Enter system name for review:" which is then followed by more questions. The script does not expect

any parameters so I cannot pass in the answers to the questions when I start the script from Perl. Is there anyway to automate such a script using perl? I have come across "expect" in

my search but I don't want to leverage any third party tools and force my end user to have to ensure that "expect" is installed on the machines if I can help it.

Thanks in advance for any help.

Zissou


FishMonger
Veteran / Moderator

Oct 27, 2008, 6:45 PM

Post #2 of 8 (1127 views)
Re: [Zissou] Automatically Answering Application Questions Using Perl [In reply to] Can't Post

Try the Expect Perl module.

http://search.cpan.org/author/RGIERSIG/Expect-1.21/Expect.pod
http://search.cpan.org/~djerius/Expect-Simple-0.04/lib/Expect/Simple.pm


KevinR
Veteran


Oct 27, 2008, 6:54 PM

Post #3 of 8 (1126 views)
Re: [FishMonger] Automatically Answering Application Questions Using Perl [In reply to] Can't Post


In Reply To
Try the Expect Perl module.

http://search.cpan.org/author/RGIERSIG/Expect-1.21/Expect.pod
http://search.cpan.org/~djerius/Expect-Simple-0.04/lib/Expect/Simple.pm


At the end of his post he says he doesn't want to use Expect.
-------------------------------------------------


FishMonger
Veteran / Moderator

Oct 27, 2008, 8:15 PM

Post #4 of 8 (1120 views)
Re: [KevinR] Automatically Answering Application Questions Using Perl [In reply to] Can't Post


In Reply To

In Reply To
Try the Expect Perl module.

http://search.cpan.org/author/RGIERSIG/Expect-1.21/Expect.pod
http://search.cpan.org/~djerius/Expect-Simple-0.04/lib/Expect/Simple.pm


At the end of his post he says he doesn't want to use Expect.


My understanding was that he didn't want to use /usr/bin/expect. The Expect.pm module is not a wrapper around the system's expect utility.

Partial quote from the module's doc.

Quote
Expect itself doesn't have real system dependencies, but the underlying IO::Tty needs pseudoterminals. IO::Stty uses POSIX.pm and Fcntl.pm.



Zissou
New User

Oct 28, 2008, 6:44 AM

Post #5 of 8 (1109 views)
Re: [Zissou] Automatically Answering Application Questions Using Perl [In reply to] Can't Post

Yes, I was trying to do this without using Expect. If there is any method other then Expect that can do this, it is the route I would prefer to take.

Thanks for everyones reply.

Best Regards,

Zissou


(This post was edited by Zissou on Oct 28, 2008, 6:46 AM)


FishMonger
Veteran / Moderator

Oct 28, 2008, 7:13 AM

Post #6 of 8 (1106 views)
Re: [Zissou] Automatically Answering Application Questions Using Perl [In reply to] Can't Post

You'll probably need to roll your own and duplicate some or most of what the Expect.pm module does.

For a start, see if these help.
http://www.perl.com/doc/manual/html/pod/perlipc.html#Bidirectional_Communication_with
http://search.cpan.org/~rgarcia/perl-5.10.0/lib/IPC/Open2.pm
http://search.cpan.org/author/RGIERSIG/IO-Tty-1.07/Tty.pm
http://search.cpan.org/~rgiersig/IO-Tty-1.07/Pty.pm


Zissou
New User

Oct 28, 2008, 7:20 AM

Post #7 of 8 (1104 views)
Re: [FishMonger] Automatically Answering Application Questions Using Perl [In reply to] Can't Post

Thank you for the direction Fishmonger. Rolling my own sounds like the perfect route.

Thanks,

Zissou


Zissou
New User

Oct 29, 2008, 6:08 AM

Post #8 of 8 (1097 views)
Re: [Zissou] Automatically Answering Application Questions Using Perl [In reply to] Can't Post

For those who are interest I have a solution that does not involve Expect. I used the example posted here http://perldoc.perl.org/perlipc.html#Bidirectional-Communication-with-Another-Process as template. open2(<reader?, <writer>, <cmd>) was the key once I figured out the I needed to declare the reader and writer before I used them in the open2 function. I had to use getc because by just accessing the reader the program was hanging when it did not receive \n

Here is the code:
$pid = open2($Reader, $Writer, "./<program or cmd to run>");
$Writer->autoflush(1);
$question = "";


while ($got = getc $Reader){
print "got a char: $got\n";
$question .= "$got";

if ($got eq "\n"){
$question = "";
}

if ($question eq "Some question 1 ") {
print "found what i was looking for\n";
print $Writer "Answer to question 1\n";
} elsif ($question eq "Some question 2 " ) {
print $Writer "Answer to question 2\n";
} elsif ($question eq "Some question 3 ") {
print $Writer "Answer to question 3\n";
last;
}
}

close Reader;
close Writer;

Best Regards,

Zissou


(This post was edited by Zissou on Oct 29, 2008, 6:14 AM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives