Helping ordinary people create extraordinary websites!

Go Back   Web Development Forum > Website Programming > Server-Side Scripting
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-12-2005, 02:33 AM
Junior Member
 
Join Date: Dec 2005
Posts: 1
Question How to read and write to an external program using Perl ?

Hi

There is en htpasswd.exe file used by apache server located in Bin directory. This file is used in order to handle different login functions on the server. I have tried to communicate with this exe using my perl script that looks like this:

#!C:\Perl\bin\perl.exe
# funktion.pl
use strict;
use warnings;
use IO::Handle;
use File::Spec;
use CPAN;

use Win32::Registry;

system ('C:\Perl\eg\htpasswd.exe -b logg user passwd'); #this one works but i would like to be more flexible and do it like this:


$str = 'C:\Perl\eg\htpasswd.exe -b logg user passwd';
system ($str);
#this one doesn't work, WHY ?

Is there any other (better) way of opening, reading and writing to an external program using Perl.

Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-26-2006, 04:41 AM
Junior Member
 
Join Date: Feb 2006
Posts: 2
Default

Code:
use IO::Handle;
use File::Spec;
use CPAN;
use Win32::Registry;
You do not need to use any of those modules.

Quote:
system ('C:\Perl\eg\htpasswd.exe -b logg user passwd'); #this one works but i would like to be more flexible and do it like this:

$str = 'C:\Perl\eg\htpasswd.exe -b logg user passwd';
system ($str);
#this one doesn't work, WHY ?
There is no difference between the two. However, the better way to do it would be along the lines of
Code:
$program = 'C:\\Perl\\eg\\passwd.exe'; # there's not a difference between '\b' and '\\b', but there is a difference between '\\' and '\'
@params = qw/-b logg user password/;
system ($program, @params);
This is more efficient because it does not require perl to pass the command to a command interpreter (cmd).


If you get an error along the lines of
Quote:
Global symbol "$str" requires explicit package name at funktion.pl line 15.
Execution of funktion.pl aborted due to compilation errors.
this is because you are 'use'ing strict vars (this is good). Define $str like 'my $str = ...' instead.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 02:11 AM.


Website Design by Ducani Media Group
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.