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!

Problems with parsing text

Status
Not open for further replies.
Oct 11, 2006
76
US
I'm trying to set up a script that will look up the port for a given extension # on a Meridian 1 PBX. Once it does so, I need the script to look for the port number and then delete the port programming. Unfortunately, I cannot get the script to "see" the lines of code that designate the port.

Here's the printout that the script will see:

REQ: PRT - these responses are ented by the script
TYPE: DNB

MARP NOT ACTIVATED

CUST 0
DN 2233
DATE
PAGE
DES
- response from PBX starts here
DN 2233
CPND
NAME John Smith
XPLN 13
DISPLAY_FMT FIRST,LAST
TYPE SL1
TN 036 0 06 01 KEY 00 H MARP DES PR5562 9 OCT 2006
(3904)

-response ends here

The line that starts with TN is where I want to start analyzing what comes in from the PBX. I'm using a WAITFOR to watch for the TN entry and then using an RGET to read the rest of the line. I may need to have multiple such lines read as I'm looking for the line with the entry MARP in it.

Here's the script so far...


string dn="2233", tn, readline, isthisthemarp, marp="marp"
integer marpnotfound=1

proc main
set txpace 50
call FindDN
call TNextract
; call OutTN [disabled for debugging]
set txpace 0
endproc

Proc FindDN

; SDLGINPUT "DN entry" "Please enter the number you want to look up " dn ;[disabled for debugging]
transmit "LD 20^M"
waitfor "REQ"
transmit "PRT^M"
waitfor "TYPE: "
transmit "DNB^M"
waitfor "CUST "
transmit "0^M"
waitfor "DN "
transmit dn
transmit "^M"
waitfor "DATE "
transmit "^M"
waitfor "PAGE "
transmit "^M"
waitfor "DES "
transmit "^M"
waitfor "NACT "
transmit "^M"
endproc

Proc TNextract
; while marpnotfound = 1
; usermsg "starting TNextract"
waitfor "TN" ;looking for the lines with the TN in them [THIS WAITFOR NEVER TRIGGERS]
rget readline ;read the rest of the line
usermsg "here's the line %20.10s" readline
substr isthisthemarp readline 25 4 ;does this line have MARP in it?
IF strcmp isthisthemarp marp ;if this is the MARP entry
usermsg "this is the MARP"
substr TN readline 4 11 ;extract the TN
usermsg "the TN is %s" TN
MarpNotFound=0 ;get out of the WHILE DO since we've found it.
endif
; endwhile
endproc



Unfortunately, the WAITFOR in procedure TNextract never triggers. Any suggestions on what I'm doing wrong?
 
Here's my $.02 worth.

Use 'forever' after your waitfor commands (so it doesn't time out.) That's probably not your problem here, but it can cause you wierd issues at times.

It might be easier to capture the output to a file, and parse that line by line.
 
Yeah, timing out is NOT my problem. *wry grin* It times out about 30 seconds after the text has gone across the screen. I've actually started writing the code to capture it all to a file, so we're apparently thinking alike there. :)

Thanks anyway.

Ross
 
In the FindDN procedure, you are waiting for NACT, but I don't see that string in the sample data you posted. What is possibly happening is that the PBX is proceeding further than you think and sending the TN string while you are waiting for NACT. This would keep the script from triggering on the TN string as it would have already been received while waiting for NACT.

 
Oops. Looks like I didn't get all the text in my cut & paste. Here's the correct text:


DN 2233
CPND
NAME Ross Schacher
XPLN 13
DISPLAY_FMT FIRST,LAST
TYPE SL1
TN 036 0 06 01 KEY 00 H MARP DES PR5562 9 OCT 2006
(3904)


NACT
REQ:

Viewing the captured text file shows that I'm capturing the text OK. So that's not an issue, thank G-d.

Meanwhile, I'm having trouble saving this to the correct file. I can't seem to convince the script to use the capture file I want it to use; it uses a file based on the name in the dialing directory of the system I'm calling and keeps incrementing it (worces01, worces02, etc). So OK, I'll use a FETCH statement to get the name of the file and edit that... and I don't seem to be getting any result from the FETCH statement. Just none at all, which leads to ERROR 5's when I try to open it.

Here's the applicable code...

string dn="2211", tn, readline, isthisthemarp, marp="marp", dnlist="ralph"
integer marpnotfound=1

proc main
set txpace 10
call FindDN
call SaveTNprintout
set txpace 0
endproc

Proc FindDN
[omitted for brevity]
endproc

Proc SaveTNPrintout
capture on
waitfor "NACT " 5
fetch capture file dnlist ;apparently, this line is not doing what I want it to do...
capture off

usermsg "the name of the capture file is %s" dnlist

fopen 0 dnlist read
while not feof 0
fgets 0 readline
substr isthisthemarp readline 25 4
IF strcmp isthisthemarp marp
usermsg "this is the MARP"
substr TN readline 4 11
usermsg "the TN is %s" TN
endif
endwhile
fclose 0
endproc
 
Code:
set capture path "C:\"
set caputre file "test_file.txt"

capture on
....
capture off
 

Sorry, typo there:
set caputre file "test_file.txt"
Should be:
set capture file "test_file.txt"

You can set the path and file name to whatever you want this way.
 
Got it working... did some searching through other threads looking for "capture" and "fetch".

Here it is in (almost) all it's kludgy glory. Just need to add a section of code to save the printed TN.

;Script to look up a MARPed DN, out the TN and add a DSC for the DN.

string dn, tn, readline, isthisthemarp, marp="MARP", SetType
integer marpnotfound=1

proc main
Call SetupProc
call FindDN
statmsg "DN found"
call SaveTNprintout
call OutTN
call buildDSC
set txpace 0
endproc

Proc SetupProc
delfile "c:\downloads\temp.txt"
set txpace 10
set capture path "c:\downloads"
set capture file "temp.txt"
endproc

Proc FindDN
SDLGINPUT "DN entry" "Please enter the number you want to look up " dn
transmit "****^M"
transmit "LD 20^M"
waitfor "REQ"
transmit "PRT^M"
waitfor "TYPE: "
transmit "DNB^M"
waitfor "CUST "
transmit "0^M"
waitfor "DN "
transmit dn
transmit "^M"
waitfor "DATE "
transmit "^M"
waitfor "PAGE "
transmit "^M"
waitfor "DES "
transmit "^M"
waitfor "NACT "
transmit "^M"
endproc

Proc SaveTNPrintout
capture on
waitfor "NACT " 5
capture off
fopen 0 "c:\downloads\temp.txt" read
while not feof 0
fgets 0 readline
statmsg "data %s" readline
substr isthisthemarp readline 26 4
IF strcmp isthisthemarp marp
substr TN readline 5 11
statmsg "the TN is %s" TN
fgets 0 readline
substr SetType readline 6 4
exitwhile
endif
endwhile
fclose 0
waitfor "REQ: "
transmit "PRT^M"
waitfor "TYPE: "
transmit "TNB^M"
waitfor "TN "
transmit TN
transmit "^M"
waitfor "SPWD "
transmit "^M"
waitfor "DATE "
transmit "^M"
waitfor "PAGE "
transmit "^M"
waitfor "DES "
transmit "^M"
waitfor "NACT "
transmit "^M"
endproc

Proc OutTN
waitfor "REQ: "
transmit "out^M"
waitfor "TYPE: "
transmit SetType
transmit "^M"
waitfor "REQ: "
transmit "END^M"
endproc

Proc BuildDSC
transmit "^M"
waitfor "REQ "
transmit "new^M"
waitfor "CUST "
transmit "0^M"
waitfor "FEAT "
transmit "cdp^M"
waitfor "TYPE "
transmit "dsc^M"
waitfor "DSC "
transmit dn
transmit "^M"
waitfor "FLEN "
transmit "^M"
waitfor "DSP "
transmit "lsc^M"
waitfor "RLI "
transmit "17^M"
waitfor "NPA "
transmit "^M"
waitfor "NXX "
transmit "^M"
waitfor "DSC "
transmit "^M"
endproc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top