Visitor

Thursday, June 24, 2010

Debug vbscript & Jscript from Command prompt


How to debug Windows Script Host (WSH) scripts, which can be written in any ActiveX script language (as long as the proper language engine is installed), but which, by default, are written in VBScript and JScript.
There are certain flags in the registry and, depending on the debugger used, certain required procedures to enable debugging.
To debug WSH scripts in Microsoft Visual InterDev, the Microsoft Script Debugger, or any other debugger, use the following command-line syntax to start the script:

               wscript.exe //d

This code informs the user when a runtime error has occurred and gives the user a choice to debug the application. Also, the //x flag can be used, as follows, to throw an immediate exception, which starts the debugger immediately after the script starts running:
               wscript.exe //d //x 

After a debug condition exists, the following registry key determines which debugger will be used:

HKEY_CLASSES_ROOT\CLSID\{834128A2-51F4-11D0-8F20-00805F2CD064}\LocalServer32

The script debugger should be Msscrdbg.exe, and the Visual InterDev debugger should be Mdm.exe.

If Visual InterDev is the default debugger, make sure that just-in-time (JIT) functionality is enabled. To do this, follow these steps:
  1. Start Visual InterDev.
  2. On the Tools menu, click Options.
  3. Click Debugger, and then ensure that the Just-In-Time options are selected for both the General and Script categories.
Additionally, if you are trying to debug a .wsf file, make sure that the following registry key is set to 1:

HKEY_CURRENT_USER\Software\Microsoft\Windows Script\Settings\JITDebug

Wednesday, June 9, 2010

Script to send a mail


#!E:\Perl\bin -w
use MIME::Lite;
MIME::Lite->send('smtp', "mailtesthub.gmail.com", Timeout=>90);
my $MailFrom = 'test@gmail.com';
my $to_list = 'john@gmail.com';
my $cc_list = 'frank@yahoo.com';
my $subject = "hello test";
my $message = "This email was generated automatically.";
my $msg = MIME::Lite->new(
From => $MailFrom,
To => $to_list,
Cc => $cc_list,
Subject => $subject,
Type => 'TEXT',
Encoding => '7bit',
Data => $message,
);


$msg->send()

Tuesday, June 8, 2010

Sample Perl script to play with file

Script to read a file using while loop.

#!/usr/local/ActivePerl-5.8/bin/perl
if (open(MYFILE, "file1")) {
$line = ;
while ($line ne "") {
print ($line);
$line = ;
}
}

Script to write in a file

#!/usr/local/bin/perl

open (MYPIPE, "cat >hello");
print MYPIPE ("Hi, Dave! Your Perl program sent this!\n");

close (MYPIPE); 


Script to search specific word from the file.

#!/usr/local/bin/perl



print ("Word to search for $ARGV[0]\n");
$filecount = 1;
$totalwordcount = 0;
while ($filecount <= @ARGV-1)
{
unless (open (INFILE, $ARGV[$filecount]))
{
die ("Can't open input file $ARGV[$filecount]\n");
}
$wordcount = 0;
while ($line = )
{
chop ($line);
print ("Before split : $line\n");
@words = split(/ /, $line);
print ("Content is : @words\n");
$w = 1;
while ($w <= @words)
{
if ($words[$w-1] eq $ARGV[0])
{
$wordcount += 1;
}
$w++;
}
}
print ("occurrences in file $ARGV[$filecount] ");
print ("$wordcount\n");
$filecount++;
$totalwordcount += $wordcount;
}
print ("total number of occurrences $totalwordcount\n");

VBscript: Sample script for msg box with class

Class Hello_World

Public Sub Say_Hello(Name)
MsgBox "Hello, " & Name & ", welcome to " & Garden & "."
End Sub
Public Garden
End Class

Dim MyHello_World

Set MyHello_World = New Hello_World

MyHello_World.Garden = "Fountain"
MyHello_World.Say_Hello "Sachin"
MyHello_World.Garden = "Foun"