http://qs1969.pair.com?node_id=887185


in reply to Re^2: Direct Connect Question
in thread Direct Connect Question

OK, this may or may not help. What you are using may behave differently from what we use. We use NDM (ndmcli). First thing is that we are capturing all the screen output to a temp file. This output includes the Process Number. What we then do is within a script run the ndmcli session and pass all the information to it using << for a "here" document in a system command. then, once that piece of the routine is finsihed, we parse the temp log file for the Process Number, store it in a variable which is then passed to a second invocation of the ndmcli so we can pull parse for Completion Code data so we know if the process worked or not. Please understand what we are doing is different from what you might be doing in that A) we run NDM on a Unix platform and B) we are doing a file transfer from Unix to a Mainframe (so there are different parameters/options for NDM). What follows is a function that I put into a custom Perl Module for my team to use so they don't have to recreate all this code every time. Also, a lot of this is based on some old code that I found that someone else wrote which I then converted from Korn Shell to use in Perl and some of it I don't quite understand but I can make educated guesses at what it is for. YMMV with the following code sample. I would suggest looking at it, if it helps, great, if not, sorry. You may also want to compare it against code samples in the C:D manuals (if you can lay your hands on them - I used to have a stack of old ones but they got purged in general office cleaning years ago). This code is mean to be run as a subroutine function from within a Perl script.

sub run_ndm { # Set NDM Environment $ENV{NDMBINDIR}=File::Spec::Unix->catdir('/',"opt","cdunix","ndm","bin +"); $ENV{NDMAPICFG}=File::Spec::Unix->catfile('/opt',"cdunix","ndm","cfg", +"cliapi","ndmapi.cfg"); $ENV{PATH}='/bin:/usr/bin:/opt/cdunix/ndm/bin'; my ($file,$process,$dataset,$blocks,$reclength,$recform)=@_; my $log=File::Spec::Unix->catfile('/',"opt","CyberFusion","log","$proc +ess.ndm.log"); my $temp=File::Spec::Unix->catfile('/',"opt","CyberFusion","log","$pro +cess.temp"); my $pnum; my $return; $dataset="$dataset(+1)" if ($_[6] =~ /G/i); umask 0110; # Printing parameters to log file. print "-" x 30; print qq/ Running with the following parameters... Process: $process File Name: $file NDM File Name: $dataset Record Format(RECFM): $recform Record Length(LRECL): $reclength Block Size(BLKSIZE): $blocks /; print "-" x 30 . "\n"; # executing NDM process system("/opt/cdunix/ndm/bin/ndmcli -x << EOJ >> $log submit $process process snode=XXXXXXXX #snode is the node ID for the d +estination step01 copy from (file=$file sysopts=\":datatype=text:\" pnode ) compress extended to (file=$dataset DCB=(RECFM=$recform,LRECL=$reclength,BLKSIZE=$blocks,DSORG +=PS) SPACE=(CYL,(000050,0000020,),RLSE,,) snode disp=(NEW,CATLG,DELETE) ) step02 if (step01 gt 4) then run task sysopts=\"echo ** File not copied, Abnormal Termi +nation **\" goto stepend eif stepend run task sysopts=\"echo ** Job Ending **\" pend; EOJ"); $|=0; #flush the print buffers sleep 300; #sleep for 300 seconds - may need to be adjusted longer to +make sure that the NDM process is complete # Try to open the log file - may want to adjust this to not die if it +cannot open the file, but instead sleep for a # specified amount of time (say 60 seconds) to give the file time to t +ransmit open LOGFILE, "$log" or die "Cannot open $log. $!"; #once we get into the log file, we grab the process number to be used +in the status check later foreach my $line (<LOGFILE>) { chomp $line; if ($line =~ /mber/) { #pnum=substr($line,-5,5); $pnum=substr($line,36); }#close if }#close inner foreach close LOGFILE; # next we will fire up the ndmcli again and dump it out to a temporary + file. system("/opt/cdunix/ndm/bin/ndmcli -x << EOJ >> $temp select statistics pnumber=($pnum) detail=YES; q; EOJ"); $|=0; #flush the buffers # now that we have the status dumped to a temp file, we have to parse +it. # to find the Completion codes. open TEMP, "$temp" or die "Cannot open $temp. $!"; # Scan each line for "Ccode" # using backreferences on the 'ccode' line, pull out the return codes. # these return codes represent the source and destination completion c +odes for both ends of the process # Both sides are added together to get one number ($return). foreach my $line (<TEMP>) { chomp $line; if ($line =~ /Ccode/) { $line=~/\w+\s+.{2}(\w+)\s+\w+\s+.{2}(\w+)/; $return=$1+$2; }# }#close foreach close TEMP; unlink $temp or die "Cannot delete $temp. $!"; ## make sure $return is a valid number. If it is not a number, then se +t it to 1 to indicate an error condition. ## if $return is NOT defined, then set $return to 1 to raise an error +in the calling script. if ( ! defined $return) { $return=1; }#close if # finally we return to the main script and pass the value of $return b +ack to the main script for evaluation. # Doing this will require a modification to the scripts to properly ev +aluate $return. See template script for # details on doing this. return $return; }