$login="vpnclient.exe connect \"VPN NAME\" user \"username\" pwd \"password\" ";
system ("exit");
system ($login);
After the connection is secure, I get a "Do you wish to continue prompt? y/n." This is probably not the best way to do it. It is simple and amateur, but jumping into Expect is pretty far above my head right now. If Expect is the only way, then I will dig in and read up, but I was looking for options on how else I can run the vpn client or get past the y/n prompt.
Eric
use Expect;
system('exit');
my $exp = Expect->new;
$exp->spawn(
'vpnclient.exe connect "VPN NAME" user "username" pwd "password"'
);
$exp->expect( 10, [ qr/Do you wish to continue/i =>
sub { $exp->send('y'); $exp->exp_continue; } ] );
Check out the faq entry
8.25: How can I capture STDERR from an external command?
You can also use the Searchbox and search for "IPC".
A super-simplified barebones example is below. IPC::OPen3 may not work in your particular case, and there can be many reasons why. In a real situation, you need to process the STDOUT and STDERR outputs with alot of regex's, then determine what reply to send to STDIN.
#!/usr/bin/perl
use warnings;
use strict;
use IPC::Open3;
#interface to "bc" calculator
#my $pid = open3(\*WRITE, \*READ, \*ERROR,"bc");
my $pid = open3(\*WRITE, \*READ,0,"bc");
#if \*ERROR is false, STDERR is sent to STDOUT
while(1){
print "Enter expression for bc, i.e. 2 + 2\n";
chomp(my $query = );
#send query to bc
print WRITE "$query\n";
#give bc time to output
select(undef,undef,undef,.5);
#get the answer from bc
chomp(my $answer = );
print "$query = $answer\n";
}
waitpid($pid, 1);
# It is important to waitpid on your child process,
# otherwise zombies could be created.
perlmonks.org content © perlmonks.org and friedo, madbombX, russH3, zentara
prlmnks.org © 2006 edmund von der burg (eccles & toad)
v 0.03