Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exit procomm at time range

Status
Not open for further replies.

zeroendless

Programmer
Mar 20, 2003
23
US
I have the window task scheduler exe a batch file to perform a dial up connection with Procomm Plus and capture file. How do i exit and terminate Procomm plus if the job is not completed at certain time range, say 10 minutes. Or better if error occurred, can't get the connection or terminal busy, terminate procomm plus.

Another option is to terminal the procomm plus on the batch file, any input is appreciated

Thk in advance
 
You will need to use the pwexit command to exit Procomm.

To determine when 10 minutes has elapsed you could assign the value of the system variable $LTIME to a long variable, then add 600 (600 second = 10 minutes). Then compare $LTIME to that long variable while in a loop. When $LTIME is equal to or greater than the value in the long variable, ten minutes will have elapsed. Something like the code below should work:

proc main
long lTimeVal

lTimeVal = $LTIME + 600
while 1
if $LTIME >= lTimeVal
exitwhile
endif
endwhile
pwexit
endproc

If you want your script to exit ten minutes after it was started, then I would insert the commands you are interested in between the lTimeVal = $LTIME + 600 and while 1 lines.
aspect@aspectscripting.com
 
You can use the when command to handle script errors, time elapsed, no activity, and response handling and the pwexit command to close your Procomm session. Check the example below.

Code:
integer active = 1
integer timelimit = 600                               ;Set timeout to 10 minutes

proc main
when $ERRORNUM call ErrorHandle                       ;Error Handling
when QUIET timelimit call NoActivity                  ;No Activity Handling
when ELAPSED 0 timelimit call TimedOut                ;Timeout Handling
when TARGET 1 "Connection refused" call NoProgress    ;Response Handling
while active
   yield
endwhile
endproc

proc ErrorHandle
active = 0
when clear
usermsg "Processing error: %i" $ERRORNUM
pwexit
endproc

proc NoActivity
active = 0
when clear
usermsg "There has been no activity for %i seconds." timelimit
pwexit
endproc

proc TimedOut
active = 0
when clear
usermsg "Session time limit of %i seconds has elasped." timelimit
pwexit
endproc

proc NoProgress
active = 0
when clear
usermsg "Your connection has been refused."
pwexit
endproc
 
Thank you, I tried both methods. mrnoisy's script seems to work better where i like timeout feature.

I created the situation where no dial tone avaliable and the script disn't exit after time expired

Is there a way to use $Carrier to check if no connection, exit the program with When statement?
such as

when !$carrier call Noconnection

proc Noconnection
active = 0
when clear

pwexit
endproc
 
You can check for $CARRIER by eiter checking to see if it's 1 (meaning a connection is established), or you can use when $CARRIER to call a procedure. The way the when command works with system variables is that the procedure is called whenever the value of the system variable changes. Thus, you would need to check the value of $CARRIER (either 1 or 0) in the procedure you call before you execute all of the commands in that procedure. Something like:

proc name
if $CARRIER == 1
commands go here...
endif
endproc

should work. aspect@aspectscripting.com
 
If you include if !$CARRIER in your while loop, it should work similar to the when command and fire off when carrier drops.

Code:
while active
   yield
   if !$CARRIER
      NoCarrier()
   endif
endwhile
 
Thank guys, it works great but if dial up is not success due to no dial tone. the script will stop after 5 attempts then Procomm plus hang. I think I'm just paranoid, try doing so much for safe guard.

The reason is in the batch file i call up another script right after first script ( short delay ) But the 2nd script won't run if the procomm is still running or open

it's a way to check if procomm plus is running or not, shut it off before exe another script.

thx again
 
From what I can gather, I assume that you are using a .bat or a .cmd file to execute procomm with your script as an argument. The problem with this is that the batch file will not wait till the procomm session is over before continuing processing.

If this is the case, I would recommend that you either create a master script to execute both your scripts or else execute/chain your second script from the first. The advantages of doing this are;[ol][li]You are not stopping and re-starting a Procomm session[/li]
[li]You can use exit codes for better script handling.[/li][/ol]For instance, your master script could look like the following;
Code:
proc main
dialnumber data "1234567890"
while $DIALING
   yield
endwhile
if $CARRIER
   execute "first.wax"
   if $EXITCODE >= 1
      errormsg "first.wax experienced an error: %i" $EXITCODE
   else
      execute "second.wax"
   endif
else
   errormsg "No carrier detected, script aborted" $EXITCODE
endif
pwexit
endproc
In your executed scripts, you can pass back exit codes depending on the results

Code:
integer active = 1, errorcode

proc main
when AAA call aaa  ; returns error code of 0
when BBB call bbb  ; returns error code of 1
while active
   yield
endwhile
exit errorcode
endproc

proc aaa
when clear
errorcode=0,active=0
endproc

proc bbb
when clear
errorcode=1,active=0
endproc
As for checking to see if a procomm script is still running, one method could be to have your script create a flag file at the beginning of the script, and then delete it at the end of your script. Your batch file can then check for the existence of the flag file to determine if the script has completed or is still running.

Example batch file
Code:
@echo off
set FLAGFILE=myflag.txt
pw5.exe myscript.wax
:start
rem  Enter some delay...
if exist %FLAGFILE% goto start
rem continue processing...

Example script file
Code:
string FLAGFILE="myflag.txt"

proc main
fopen 0 FLAGFILE create text
fclose 0
;
; Process script
;
delfile FLAGFILE
endproc
 
---------------------------------------------------
1st exe to access terminal and capture file

integer active = 1
integer timelimit = 60

proc main
when $ERRORNUM call ErrorHandle
when QUIET timelimit call NoActivity
when ELAPSED 0 timelimit call TimedOut
when TARGET 1 "INVALID LOG-ON ATTEMPT PLEASE RETRY" call NoProgress


sendkey ALT 'D'
sendvkey 0x09
sendvkey 0x09
sendvkey 0x09
sendvkey 0x0D

waitfor "Procomm Plus Ready!^M^J"
transmit "^M~~^M"
waitfor "Host Name: "
transmit "xxxx^M"
waitfor "CUSTOMER ID: "
transmit "xxxx^M"
waitfor "CUSTOMER PASSWORD: "
transmit "xxxx^M"
waitfor "OPERATOR ID: "
transmit "xxxx^M"
waitfor "OPERATOR PASSWORD: "
transmit "xxxx^M"
waitfor "DESIRED SERVICE: "
transmit "xxxx^M"
waitfor "READY INPUT DEVICE - ENTER A CARRIAGE RETURN TO BEGIN REPORT "
clear
capture on
transmit "^M"
waitfor "DESIRED SERVICE: "
capture off
transmit "bye^M"
disconnect

while active
yield
if !$CARRIER
NoActivity()
endif
endwhile


endproc

proc ErrorHandle
active = 0
when clear
;usermsg "Processing error: %i" $ERRORNUM
pwexit
endproc

proc NoActivity
active = 0
when clear
;usermsg "There has been no activity for %i seconds." timelimit
pwexit
endproc

proc TimedOut
active = 0
when clear
;usermsg "Session time limit of %i seconds has elasped." timelimit
pwexit
endproc

proc NoProgress
active = 0
when clear
;usermsg "Your connection has been refused."
pwexit
endproc
--------------------------------------------------
2nd exe to check file, verify if file is corrupted or completed. set flag file for error, success or no record found in captured file.


string Flagerror ="C:\Program Files\Symantec\Procomm Plus\Aspect\Capture\Flagerr.txt"
string Flagsuccess ="C:\Program Files\Symantec\Procomm Plus\Aspect\Capture\Flagsuc.txt"
string File1 ="C:\Program Files\Symantec\Procomm Plus\Aspect\Capture\capture.txt"
string CopyFile2 ="C:\Program Files\Symantec\Procomm Plus\Aspect\Capture\pdr.txt"
string Flagnullrecord ="C:\Program Files\Symantec\Procomm Plus\Aspect\Capture\Flagnull.txt"
string LineToCopy
string LineCopy
string sTok1
string sTok2
integer iCount = 0
integer totalRecord
integer numOf99 = 0
integer acount = 0
integer check = 0
proc main


if isfile File1
fopen 1 File1 read text
fopen 2 CopyFile2 create text

while not feof 1
fgets 1 LineToCopy
LineCopy = LineToCopy

strtok sTok1 LineToCopy "," 1
if strfind sTok1 "01"
fputs 2 LineCopy
iCount++
endif
if strfind sTok1 "02"
fputs 2 LineCopy
iCount++
endif
if strfind sTok1 "03"
fputs 2 LineCopy
iCount++
endif
if strfind sTok1 "88"
fputs 2 LineCopy
iCount++
endif
if strfind sTok1 "16"
fputs 2 LineCopy
acount++
iCount++

endif
if strfind sTok1 "49"
fputs 2 LineCopy
iCount++
endif
if strfind sTok1 "98"
fputs 2 LineCopy
iCount++
endif
if strfind sTok1 "99"
fputs 2 LineCopy
numOf99++
iCount++
strtok sTok2 LineToCopy "," 3
atoi sTok2 totalRecord
endif


endwhile

fclose 2
fclose 1
else
Errorflag()
endif

if iCount == totalRecord && numOf99 != 0 && acount != 0
fopen 3 Flagsuccess create text
fputs 3 sTok2
fclose 3

elseif iCount == totalRecord && numOf99 != 0 && acount == 0
fopen 5 Flagnullrecord create text
fclose 5
else
Errorflag()

endif



pwexit
endproc

proc Errorflag
fopen 6 Flagerror create text
fputs 6 sTok2
fclose 6
endproc
----------------------------------------------------------

Here is what i have and it's working fine with the helps from this forum(thank you) and the 720 pages menu. Basically, File is captured from terminal from 1st exe,trimed to eliminated all junk screen prints, created flag file accordingly from captured file.

the batch file will
1) delete all file, including the flag
delay
2) exe script to access terminal,capture file
delay
3) exe 2nd script to validate capture file, set flagfile
delay
4) condition to exe steps depend on flagfile

the flagerr.txt is to call the batch file again if download not completed or corruptted file or earlier termination due to error from 1st exe.
ps, i used sendkey to call the connection direcotry , sounds funny but is the only way i know how to get it to work.
more detail, the final capture file is
.................................
01,xxx,xxx,030327,1428,012,80,1,2/
02,xxx,xxx,1,030326,1428,USD,1/
03,xxxx,USD,15,2141,,Z,20,1100,,Z,25,400,,Z,40,2141,,Z,45,2141,,Z,50/
16,xx,333,33444,/
88,1100,,Z,55,400,,Z,72,0,,Z,74,0,,Z,75,0,,Z,100,0,0,Z,182,0,,Z,400,0,0,Z,482/
88,0,,Z/
49,9423,4/
98,9423,1,6/
99,9423,1,8/
............................
if record 16 not there, flagnull is set
if total record last item from string 99 not equal to count from 01-99, file not completed, flagerr is set
else
flagsuc is set
----------------------------
everthing seems to works fairly well, i'm just concerning if no dial tone or can't get the connection, how to get the procomm session off. so the 2nd exe can be exe.

thx again

 
Is there any reason why you cannot combine the two scripts? If not, then maybe the following script may suit your needs. It should handle both of your required tasks as well as handle any non-connections (i.e, No Dial Tone, Busy, etc.)
Code:
integer totalRecord
string  LineToCopy, LineCopy, sTok1, sTok2

integer active         = 1
integer timelimit      = 60
integer iCount         = 0
integer numOf99        = 0
integer acount         = 0
integer check          = 0
string  CAPTUREPATH    = $ASPECTPATH
string  Flagerror      = "Flagerr.txt"
string  Flagsuccess    = "Flagsuc.txt"
string  File1          = "capture.txt"
string  CopyFile2      = "pdr.txt"
string  Flagnullrecord = "Flagnull.txt"

#define Tx(a,b)        transmit a # transmit "^M" # waitfor b

proc main
InitializeFile()
DialCustomer("Your Dialling Directory Entry Name")
if $CARRIER == 1
   StartCapture("Hostname","CustID","CustPw","OpID","OpPw","Service")
else
   ;No carrier detected
endif
when clear
ProcessCall()
pwexit
endproc

proc InitializeFile
addfilename CAPTUREPATH "Capture"
strfmt Flagerror      "%s\%s" CAPTUREPATH Flagerror
strfmt Flagsuccess    "%s\%s" CAPTUREPATH Flagsuccess
strfmt File1          "%s\%s" CAPTUREPATH File1
strfmt CopyFile2      "%s\%s" CAPTUREPATH CopyFile2
strfmt Flagnullrecord "%s\%s" CAPTUREPATH Flagnullrecord
endproc

proc DialCustomer
param string CustName
dialload $DDIRFNAME
dial data CustName
while $dialing
   yield
endwhile
endproc

proc StartCapture
param string Hostname, CustID, CustPw, OpID, OpPw, Service
when $ERRORNUM call StopProcessing
when QUIET timelimit call StopProcessing                
when ELAPSED 0 timelimit call StopProcessing               
when TARGET 1 "INVALID LOG-ON ATTEMPT PLEASE RETRY" call StopProcessing    
Tx("^M~~","Host Name: ")
Tx(Hostname,"CUSTOMER ID: ")
Tx(CustID,"CUSTOMER PASSWORD: ")
Tx(CustPw,"OPERATOR ID: ")
Tx(OpID,"OPERATOR PASSWORD: ")
Tx(OpPw,"DESIRED SERVICE: ")
Tx(Service,"READY INPUT DEVICE - ENTER A CARRIAGE RETURN TO BEGIN REPORT")
clear
capture on
Tx("","DESIRED SERVICE: ")
capture off
transmit "bye^M"
disconnect
while active
   yield
   if !$CARRIER
      StopProcessing()
   endif
endwhile
endproc

proc ProcessCall
fopen 2 CopyFile2 create text 
fclose 2
if fopen 1 File1 read text    
      while not feof 1          
         fgets 1 LineToCopy
         LineCopy = LineToCopy
         strtok sTok1 LineToCopy "," 1
         AppendLog(sTok1,"01")
         AppendLog(sTok1,"02")
         AppendLog(sTok1,"03")
         AppendLog(sTok1,"88")
         AppendLog(sTok1,"16")
         if strfind sTok1 "16" 
            acount++
         endif 
         AppendLog(sTok1,"49")
         AppendLog(sTok1,"99")
         if strfind sTok1 "99" 
            numOf99++
            strtok sTok2 LineToCopy "," 3
            atoi sTok2 totalRecord
         endif
      endwhile
   fclose 2                 
   fclose 1  
else
    Errorflag()
endif
if iCount == totalRecord && numOf99 != 0 && acount != 0
    fopen 3 Flagsuccess create text
       fputs 3 sTok2
    fclose 3
elseif iCount == totalRecord && numOf99 != 0 && acount == 0
    fopen 5 Flagnullrecord create text
    fclose 5
else
    Errorflag()
endif 
endproc

proc AppendLog
param string TokenExtracted, TokenToMatch
if strfind TokenExtracted TokenToMatch 
   fopen 2 CopyFile2 append text 
   fputs 2 LineCopy
   iCount++  
endif  
endproc

proc StopProcessing
active = 0
endproc

proc Errorflag
fopen 6 Flagerror create text 
   fputs 6 sTok2
fclose 6
endproc
 
wow, your code is well written, very profession.
sorry, i marked the id and password with xxxx due to the confidentiality of my client i can't post it here.
say the
Hostname is abc
CustID is 1234
CustPw is 1234
OpID is 1234
OpPw is dec
Service is ted1
the CustID,CustPw and OpPw has same value but it's a numeric value which contain no character
i changed the variables according to my data and having trouble compiling on line: param string abc,1234, 1234, 1234,dec , ted1
Error message :
Invalid identifier or name: 1234
Invalid identifier or name: 1234
Invalid identifier or name: 1234
i suppose you can't assign numberic to string as well as having 3 variables with same name 1234??
 
Me Again, I was going over the example I posted earlier and noticed a couple of flaws. Here is an updated version. It should work but as I can't test it, I cant make any guarantees.

By the way, what type of delay are you using in your batch file to allow the script to complete? If you create a running flag file at the begining of the main proc and delete it just before the pwexit command, your batch file can check for the existance of the flag file to know when the script is complete.

Code:
integer totalRecord
string  LineToCopy, LineCopy, sTok1, sTok2

integer active         = 1
integer timelimit      = 60
integer iCount         = 0
integer numOf99        = 0
integer acount         = 0
integer check          = 0
string  CAPTUREPATH    = $ASPECTPATH
string  Flagerror      = "Flagerr.txt"
string  Flagsuccess    = "Flagsuc.txt"
string  File1          = "capture.txt"
string  CopyFile2      = "pdr.txt"
string  Flagnullrecord = "Flagnull.txt"

#define Tx(a,b)        transmit a # transmit "^M" # waitfor b

proc main
InitializeFile()
DialCustomer("Your Dialling Directory Entry Name")
if $CARRIER == 1
   StartCapture("Hostname","CustID","CustPw","OpID","OpPw","Service")
   when clear  ; Moved
   disconnect  ; Added as failsafe
else
   ;No carrier detected
endif
ProcessCall()
pwexit
endproc

proc InitializeFile
addfilename CAPTUREPATH "Capture"
strfmt Flagerror      "%s\%s" CAPTUREPATH Flagerror
strfmt Flagsuccess    "%s\%s" CAPTUREPATH Flagsuccess
strfmt File1          "%s\%s" CAPTUREPATH File1
strfmt CopyFile2      "%s\%s" CAPTUREPATH CopyFile2
strfmt Flagnullrecord "%s\%s" CAPTUREPATH Flagnullrecord
endproc

proc DialCustomer
param string CustName
dialload $DDIRFNAME
dial data CustName
while $dialing
   yield
endwhile
endproc

proc StartCapture
param string Hostname, CustID, CustPw, OpID, OpPw, Service
set aspect errormsg off  ;**left out, turns of error dialogs
when $ERRORNUM call StopProcessing
when QUIET timelimit call StopProcessing                
when ELAPSED 0 timelimit call StopProcessing               
when TARGET 1 "INVALID LOG-ON ATTEMPT PLEASE RETRY" call StopProcessing    
while active && $CARRIER     ; Included $CARRIER in while condition
   Tx("^M~~","Host Name: ")  ; and moved location.
   Tx(Hostname,"CUSTOMER ID: ")
   Tx(CustID,"CUSTOMER PASSWORD: ")
   Tx(CustPw,"OPERATOR ID: ")
   Tx(OpID,"OPERATOR PASSWORD: ")
   Tx(OpPw,"DESIRED SERVICE: ")
   Tx(Service,"READY INPUT DEVICE - ENTER A CARRIAGE RETURN TO BEGIN REPORT")
   clear
   capture on
   Tx("","DESIRED SERVICE: ")
   capture off
   transmit "bye^M"
   disconnect
   pause timelimit ; Added, allow time to disconnect.
;   if !$CARRIER   ;No longer required (Added as while condition)
;      StopProcessing()
;   endif
endwhile
endproc

proc ProcessCall
fopen 2 CopyFile2 create text 
fclose 2
if fopen 1 File1 read text    
   while not feof 1          
      fgets 1 LineToCopy
      LineCopy = LineToCopy
      strtok sTok1 LineToCopy "," 1
      AppendLog(sTok1,"01")
      AppendLog(sTok1,"02")
      AppendLog(sTok1,"03")
      AppendLog(sTok1,"88")
      AppendLog(sTok1,"16")
      if strfind sTok1 "16" 
         acount++
      endif 
      AppendLog(sTok1,"49")
      AppendLog(sTok1,"99")
      if strfind sTok1 "99" 
         numOf99++
         strtok sTok2 LineToCopy "," 3
         atoi sTok2 totalRecord
      endif
   endwhile
;  fclose 2 ; Not required
   fclose 1 
else
    Errorflag()
endif
if iCount == totalRecord && numOf99 != 0 && acount != 0
    fopen 3 Flagsuccess create text
       fputs 3 sTok2
    fclose 3
elseif iCount == totalRecord && numOf99 != 0 && acount == 0
    fopen 5 Flagnullrecord create text
    fclose 5
else
    Errorflag()
endif 
endproc

proc AppendLog
param string TokenExtracted, TokenToMatch
if strfind TokenExtracted TokenToMatch 
   fopen 2 CopyFile2 append text 
      fputs 2 LineCopy
   fclose 2  ;** left out, fatal flaw. duh
   iCount++  
endif  
endproc

proc StopProcessing
disconnect   ;** left out
active = 0
endproc

proc Errorflag
fopen 6 Flagerror create text 
   fputs 6 sTok2
fclose 6
endproc
 
I posted my new example before I saw your post. Do not modify the param string, but set your variables in the StartCapture proc

ie. StartCapture("abc",","1234","1234","1234","dec")

that goes the same for the DialCustomer, replace it for your dialing directory entry name.

I wrote the script this way because I wasn't to sure whether there was only one or more sites you were connecting to. This way the code is more flexible. Sorry if the code intimidated you, it just makes it easier to see what the script is doing when its not so messy, if you know what I mean. If there is anything else in the code you want to no about it, just ask. :)
 
PS: You mentioned that you didn't know how to dial a directory entry other then using sendvkey, well the DialCapture proc shows you how.

In the DialCustomer proc, I used dialload $DDIRFNAME to load the current directory. This is not neccessary if you on have the one directory. If you have more than one, you could replace the $DDIRFNAMR with name of the dialing directory you want to load (in quote ie dialload "pw5.dir").
 
awesome, the modifed codes worked great. i leave the param string alone and changes only made to the StartCapture proc and the dialCustomer, worked.

The delay on batch file is just the wait statement. i see what are you telling here,
if(script stop running ) found flag file
exe blah blah
else
repeat checking if flag file there.

You're very sincere on explaining the codes as well, thx and i have couple questions here

1) if no dial tones, procomm keeps on dialing forever. it's a way to stop the dial say after 5 times, so the code can exit procomm as planned.

2) this is just sample of small file, say if i have more than thousands of records(lines) to capture then exe. will i face timeout issues or need short delay between exe of 1st and 2nd scripts?

 
sorry. typo, on the last question.

i meant short delay between exe of proc StartCapture
& proc ProcessCall, we are combining 2 scripts here
 
By default I believe, Procomm will try to dial 99 times. You can change this by selecting the Options | System Options | Dialing Options menu item or using the set dial retries NN command, where NN is replaced by the number of retries you want your script to make.

I'll let mrnoisy address your second question since he will be more familiar with his script.
aspect@aspectscripting.com
 
1) Add the following to the top of the DialCustomer procedure (under the dialload command).

Code:
set dial retries 5     ;Set # of retries
set dial retrydelay 10 ;Delay between retries in seconds

2) Just after you turn the capture on, you are running the Tx function (basical transmit and waitfor combined). The standard waitfor command without and arguments, waits for 30 seconds before proceding. You could change it use to waitfor "DESIRED SERVICE: " timelimit or even waitfor "DESIRED SERVICE: " FOREVER to make it wait indefinately whilst capturing, or until a when ELAPSED or when QUIET timer steps in or carrier drops.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top