Home
TeamSite
how to debug perl scripts invoked by externaltasks
gsumers22texas
How do you set up to write to a debug output file from a secondary Perl script (say it's unlock.ipl) that is called from an externaltask in a wft?
Turning on/off the #iw_output_file helps debug the wfts, but what about more specific secondary ipls you want to use in a wft (unlock.ipl, iwpt_compile.ipl, etc)?
We want to verify some of the values being set by using the TeamSite workflow modules (::Config, ::WFworkflow, ::WFtask) by those files, but we can't test by invoking the perl script independently from the command line (with the -d option), can we?
something suggested by another Perl developer (with no TeamSite workflow knowledge) is following code inserted into unlock.ipl:
.....
$|=1;
$DEBUG = 1;
$debugfile = "/tmp/debugfile.dbg";
debug("-----------------------");
debug("In unlock.ipl");
.....
debug("iw_home=$iw_home");
......
sub debug {
my $msg = shift;
if($DEBUG != 1) {
return;
}
if(-e $debugfile) {
open(THATFILE,">>$debugfile");
} else {
open(THATFILE,">$debugfile");
}
print THATFILE "$msg\n";
close(THATFILE);
}
........
but this still isn't producing our debug file-
and, isn't the -e option also a command-line directive?
is there a way to get the wf engine to recognize common perl debugging directives?
thanks for any help
Find more posts tagged with
Comments
akshathp
It seems you are just making a simple call to debug function within your ipl script. So that should work. Couple of points:
1. You could execute the ipl at command prompt just to see if it has any PERL syntax errors or not. Although the script if *not encountered* any syntax error will stop and look for TaskID and WorkflwID but atleast this way we can eliminate the doubt of syntax errors.
2. I am sure you would have checked the write permissions on the /tmp/.
Just my 2 cents before we move further.
Hope this helps.
Akshat Pramod Sharma
Interwoven Inc.
Migrateduser
If you put a plain "print" statement into the perl script and the script is executed by the workflow engine, the output usually ends up in the iwtrace log. I think you can also redirect the output using something like this:
open STDERR, ">/tmp/err.log" or die "Can't open error log: $!\n";
open STDOUT, ">/tmp/out.log" or die "Can't open error log: $!\n";
I have not redirected my STDOUT/ERR for awhile, but I'm pretty sure it works.
You can also run the script on the command line as if they are being run by the workflow engine. Before the workflow starts, do something to the external script so the script will error out such as take away the execute bit, munge the path to perl, etc.
After the script fails to execte, the workflow will hang. Go to the todo list and find the job id and task id of the current workflow and run your script passing in the following to the script:
jobid taskid areapath
or
./unlock.ipl 345 334 /default/main/test/WORKAREA/jmichnow
That script will now run on the command line and get everything that the workflow would pass it. This is a good way put in print statements to see what the script is doing. If you want to run the script many time, you should comment out the callback.
gsumers22texas
permission of /tmp/ is 777, but permissions of secondary .ipl was 744 - am changing to 777 and retesting
will try the suggestion to run directly on the Command Line passing values as suggested
gsumers22texas
Is there something that needs to be done to a new .ipl script added to /local/bin (location of unlock.ipl)
reason I ask is as follows:
I execute unlock.ipl from the command line, receive no errors
I execute our new ipl from the command line, get error:
./ourscript.ipl: not found
I even replace all code from unlock.ipl, replaced it into ourscript.ipl, and re executed, and received same error (see log below)
I also verified permissions and ownership of ourscript.ipl matched that of unlock.ipl
is there a step I'm missing to "enable" new scripts to run from this location? is it something unique to iw-perl?
# ./ourscript.ipl
./ourscript.ipl: not found
# ./unlock.ipl
--> copied unlock.ipl code into ourscript.ipl and saved
# ./ourscript.ipl
./ourscript.ipl: not found
Adam Stoller
If you want to debug an externaltask script - what I usually do is comment out the callback, run the workflow until it executes the externaltask script and then "hangs" (because there's no callback) and then run the script from the command line through the perl debugger:
iwperl -d
tkdb scriptname.ipl jobid taskid area
Then I can do interactive debugging - rather than dumping content into a file that I have to parse and figure out what's happening....
--fish
(Interwoven, Curriculum Development)
gsumers22texas
thanks for reply-
where are you invoking this from? from the iw-perl directory (/iw-home/iw-perl/bin) (with full path to "scriptname.ipl"), or from the location of scriptname.ipl? (/iw-home/local/bin for unlock.ipl, a out of the box script)
when I try to run this from either location of the script, I get message "iwperl: not found"
the shebang line of unlock.ipl is :
#!/iw-home/iw-perl/bin/iwperl
I am running it as root, and permissions of iwperl are:
-rwxr-xr-x 1 root daemon 14684 Jul 22 09:03 iwperl
I am running it as root, and permissions of ourscript.ipl are:
-rwxrwxrwx 1 root other 4729 Sep 11 17:24 ourscript.ipl
gsumers22texas
UPDATE:
I think I've got past the "script not found" problem, though don't know exactly why it works one way and not the other:
the way NOT to create a new .ipl script and get iwperl to run it:
1. create your new script, make shebang line match that of unlock.ipl --> will not execute - receive "not found" message
2. copy all code from unlock.ipl and replace all code into your script --> still will not execute, receive "not found" message
the way to create a new .ipl script and get iwperl to run it:
1. copy unlock.ipl and rename copy to your script name
2. replace all code in your script name with your original code --> it executes fine and provides debug messages
???? - not sure what difference between two steps are, but it did solve my problem
Migrateduser
I always use debug logs in all of my externaltask scripts. It may be more tedious than debugging other ways, but it has saved my **** more times than I can remember when something goes wrong or an externaltask hangs during execution of a workflow. I have a directory that contains all the debug logs for all my scripts. I print any pertinent information to the log and can easily track down a problem if it arises.
Dave Smith
Sr. Software Engineer
Nike, Inc.
(503) 671-4238
DavidH.Smith@nike.com
Adam Stoller
If you are on a Unix system - the #! line should show the path to IWHOME/iw-perl/bin/iwperl and the script must be marked as executable (chmod 755)
If you are on a Windows system - you should be able to run it as there is already an association between .ipl and iwperl and IWHOME/iw-perl/bin/iwperl. However, I like to make sure that I have IWHOME/iw-perl/bin (amongst others) in my SYSTEM PATH environment as well as adding .ipl to my SYSTEM PATHEXT environment.
In either case - assuming iwperl is on your PATH - unless the location of the script is in your PATH - you will either need to supply that information on the command line or cd to that location before attempting to run it - and you should be able to do the following:
[in directory with script]: iwperl scriptname arguments
[somewhere else]: iwperl path-to-scriptname arguments
With regard to running the debugger - you will definitely want to use one of the two above formats rather than running the script completely from the PATH as you want to invoke iwperl differently than it would be sepecified on the #! line.
<pre>
iwperl -d
tkdb scriptname arguments
iwperl -d
tkdb path-to-scriptname arguments
</pre>
And yes, Smitty, dumping data into a debugging file is often very useful and can sometime be as (or perhaps even more) effective as using the debugger- but if you're having problems figuring out what's happening in your program - the debugger is often more useful than the output file.
--fish
(Interwoven, Curriculum Development)
Migrateduser
I'm sure I would agree with you if I ever tried to use the debugger. I am ashamed to admit I have never used it.
Dave Smith
Sr. Software Engineer
Nike, Inc.
(503) 671-4238
DavidH.Smith@nike.com
Migrateduser
To gsumers22texas:
The debug subroutine that you copied is a very good way to go. Here's what it does: If the $DEBUG and if the debug file *already exists* (that's what the -e test is for), then it will (try to) write to the file.
You will need to create the empty log file (use 'touch'), or remove the -e test.
NOTE to other readers: On Windows, there is a bug (32914, fixed in 5.5.2 SP2) that kept the output from externaltasks from going into the iwtrace.log.
Brinko Kobrin
Interwoven Staff Engineer
mogoo
fish-
This looks like a nifty solution, but I get this error when I try to run it...
couldn't connect to display ":0" at /opt/iw-home/iw-perl/lib/perl5/site_perl/5.005/sun4-solaris/Tk/MainWindow.pm line 55.
MainWindow->new() at /opt/iw-home/iw-perl/lib/perl5/5.00503/Devel/ptkdb.pm line 1007
...how can I fix this, so this debugging technique works?
--TS5.5 SP1, Solaris
thanks,
maureen