Sign in to follow this  
Followers 0
DjDeep00

Convert Perl code to Autoit code

12 posts in this topic

Is anyone a Perl expert out there, who can convert the following Perl code to Autoit?

#!/usr/bin/perl -w

use strict;

use LWP::UserAgent;

use HTTP::Request::Common;

my $userAgent = LWP::UserAgent->new(agent => 'perl post');

opendir DIR, "c:/XML";

my @files = readdir(DIR);

closedir DIR;

#print $files[2];

my $x = 2;

while ( $x <= @files-1 )

{

open(DAT, "c:/XML/".$files[$x]) || die("Could not open file!");

undef $/;

my $raw_data = <DAT>;

close DAT;

$/ = "\n";

my $message = $raw_data;

#print "XML Sent: ";

#print $raw_data;

my $response = $userAgent->request(POST 'http://199.168.1.88:5555/servlet',Content_Type => 'text/xml',Content=>$raw_data);

open LOG, ">>C:/Log.txt";

print LOG $response->error_as_HTML unless $response->is_success;

print LOG $response->as_string;

close LOG;

$x = $x + 1;

}

Thanx in advance.

Share this post


Link to post
Share on other sites



Maybe for some of us that can help but dont know PERL could you explain what it does?

Share this post


Link to post
Share on other sites

It's opening all of the files in a particular folder, reading them in as raw XML and then posting them to a web address. Most of the code is just housekeeping.

Why do you want to convert it to AutoIt?

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

It's opening all of the files in a particular folder, reading them in as raw XML and then posting them to a web address. Most of the code is just housekeeping.

Why do you want to convert it to AutoIt?

Dale

DaleHohm you absolultely correct, thats exactly what I am doing.

My main reason for converting is because you wont be able to execute the perl code on any computer. You will need to install activate now for the Perl script. If I can convert it to Autoit then I can just simply compile it to one exe. Any help would be appreciated.

Share this post


Link to post
Share on other sites

Perl --> Autoit....Anyone?

Share this post


Link to post
Share on other sites

Perl --> Autoit....Anyone?

HI,

I think there are also perl2exe converter out there.

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

Is anyone a Perl expert out there, who can convert the following Perl code to Autoit?

#!/usr/bin/perl -w

use strict;

use LWP::UserAgent;

use HTTP::Request::Common;

my $userAgent = LWP::UserAgent->new(agent => 'perl post');

opendir DIR, "c:/XML";

my @files = readdir(DIR);

closedir DIR;

#print $files[2];

my $x = 2;

while ( $x <= @files-1 )

{

open(DAT, "c:/XML/".$files[$x]) || die("Could not open file!");

undef $/;

my $raw_data = <DAT>;

close DAT;

$/ = "\n";

my $message = $raw_data;

#print "XML Sent: ";

#print $raw_data;

my $response = $userAgent->request(POST 'http://199.168.1.88:5555/servlet',Content_Type => 'text/xml',Content=>$raw_data);

open LOG, ">>C:/Log.txt";

print LOG $response->error_as_HTML unless $response->is_success;

print LOG $response->as_string;

close LOG;

$x = $x + 1;

}

Thanx in advance.

The complicated piece is this line:

my $response = $userAgent->request(POST 'http://199.168.1.88:5555/servlet',Content_Type => 'text/xml',Content=>$raw_data);

Check out this desctiption of using XMLHTTP to post

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

Dale,

request(POST 'http://199.168.1.88:5555/servlet' ---> Instead of GET I am using POST.

Content_Type => 'text/xml' ---> This is a header for HTTPS.

Content=>$raw_data) ---> This is the data (xml).

I know there is some kind of xml posting code for VB that you can use.

Please let me know if you need more info on what that specfice line of code does. If you can just give it a shot and post the converted Autoit script, that would be awesome. Then I can play around with it and hopefully make it work.

Thanks in advance.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

The complicated piece is this line:

my $response = $userAgent->request(POST 'http://199.168.1.88:5555/servlet',Content_Type => 'text/xml',Content=>$raw_data);

Check out this desctiption of using XMLHTTP to post

Dale

Hmmm. I thought there was enough information at taht site for you to give it a shot... here is some help with syntax converting their example to something close for you in AutoIt:

$xml = ObjCreate("Microsoft.XMLHTTP")
$xml.Open("POST", "http://199.168.1.88:5555/servlet", False)
$xml.setRequestHeader("Content-Type", "text/xml")
$xml.Send($raw_data)

Dale

Edited by DaleHohm

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

Hmmm. I thought there was enough information at taht site for you to give it a shot... here is some help with syntax converting their example to something close for you in AutoIt:

$xml = ObjCreate("Microsoft.XMLHTTP")
$xml.Open("POST", "http://199.168.1.88:5555/servlet", False)
$xml.setRequestHeader("Content-Type", "text/xml")
$xml.Send($raw_data)

Dale

You were rite there was enough info at that site. I just needed some help with the syntax and now I am GOOD TO GO!

Thanx Dale.

Share this post


Link to post
Share on other sites

Is there a difference between "Microsoft.XMLHTTP" and "winhttp.winhttprequest"?

Share this post


Link to post
Share on other sites

Is there a difference between "Microsoft.XMLHTTP" and "winhttp.winhttprequest"?

very interesting question:

i don't know but i tested them and it appear that winhttp is more rapid and you can do a loop WinHttpReq.send() with only one call to WinHttpReq.open()

maybe other expert tell as more :whistle:

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0