Possible to parse an output file using a TextPad Tool?

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
textpadquestion
Posts: 8
Joined: Mon Jul 19, 2010 5:20 pm

Possible to parse an output file using a TextPad Tool?

Post by textpadquestion »

Hi TextPad Geniuses!

First, I love using TextPad to develop SAS programs. I have hotkey setup to batch submit from within TextPad and it's working great! I'm kind of a noob when it comes to working in the window's environment so I hope someone out there can help me. I'd like to extend this tool within TextPad (or perhaps develop a new approach) to emulate a script I had set up in the UNIX environment.

My requirements are...
1. While editing a <program>.sas file from within TextPad, be able to easily submit the program to SAS. [currently have this ability]
2. The process in #1 will create a <program>.log file. Requirement #2 is to be able to parse the <program>.log file with a predefined regular expression and be presented with either matching lines or counts of occurrences. [not able to do this currently.]

I understand that the Tool I already have set up should be able to "Capture output," but a) this option is grayed out, and b) I'm not sure the <program>.log file is what the tool would expect as "output."

I am open to all approaches that could fulfill these requirements. Thanks in advance for your time and help!
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

Write a batch file (a Windows shell script) that runs the program and then sends the log file to stdout. Use type (the Windows version of cat).

Add a DOS Command to run this batch file. Select Capture output, and set Regular expression to match output as appropriate.

If you are uncomfortable with cmd.exe (the apology for a command-line processor supplied by Microsoft), you can obtain a more familiar environment by installing cygwin (http://www.cygwin.com/), which will provide you with a bash shell and most Linux command-line tools.
textpadquestion
Posts: 8
Joined: Mon Jul 19, 2010 5:20 pm

Post by textpadquestion »

Edit: I get the results below two ways: one way is by adding a "program" to execute my batch file and the other way is by adding a "DOS Command" which may be an important part of Ben's reply, but I get the same behavior both ways. Below was written with my tool that added a "program" in mind....


This is great.
-My TextPad Tool executes my batch file with parameters: $File $BaseName.log.
-My batch file executes the program and then "type"s the log file to the cmd session.
-I'm capturing output and suppressing output until completed.

Problem is, I can't seem to get the regular expression to have any effect... the Tool Output window that opens contains all the output from the tool and not just lines that match the regular expression.

My understanding is that the File, Line, and Column registers are only of use if the matched lines contain this information as part of the matched string. So I've left those blank.

What am I missing? I feel like this is so close to working exactly as I've dreamed!


---> ---> ---> ---> ---> ---> ---> --->
Just to round out the details... for testing, I'm defining the regular expression as:
NOTE

And example output making its way from the <program>.log file into the Tool Output window now (I would expect only the first three lines):

Code: Select all

NOTE: There were 9 observations read from the data set WORK.DIFFER.
NOTE: The PROCEDURE PRINT printed page 9.
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds
User avatar
MudGuard
Posts: 1295
Joined: Sun Mar 02, 2003 10:15 pm
Location: Munich, Germany
Contact:

Post by MudGuard »

The regular expression is not for filtering lines.

It is used to jump to the error location.
Compilers usually give the file name, the line and maybe the column where the error occurred. You can then (if the regex is correct) click on the error message, and the file containing the error is opened, and the cursor placed at the line (and, if given) the column where the error occurred.

Your tool does not, as far as I can see, print error messages with file names and line numbers.
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

If you just want to see the lines matching some regular expression, run the log file through the built-in command findstr or your favourite version of grep, instead of type.
textpadquestion
Posts: 8
Joined: Mon Jul 19, 2010 5:20 pm

Post by textpadquestion »

My sincere thanks to you both for your input here.

I don't have complete control over the environment I'm working in. Ultimately, instead of using findstr I think a perl script to produce the exact output I have in mind is the best way for me to go given my experience... but I don't have free rein to install whatever the heck software I want on this particular machine, so I think I'll use FindStr for now and see how well it fits my needs.

Also, I'm an advocate for using TextPad in SAS development and I think it's unrealistic to suggest to others to "use TextPad, but by the way, you'll really need to download and install additional software too." Especially when even the idea of having to download TextPad and merely set up the tool to batch submit (without any log parsing) is sometimes too much to bear for some people.

-------------------------------------------------------

Actually, the more I think about it... there may be a relatively simple way to include an additional SAS call to parse the log from the first program and produce "output" that would contain the file and line references which could then be used by the "perl regular expression to match output" registers to accomplish my goal.

Thanks again for your time and let me know if you disagree with my outlook.
textpadquestion
Posts: 8
Joined: Mon Jul 19, 2010 5:20 pm

Post by textpadquestion »

Update:
Working like a champ with FindStr!!!! I now get clickable matching lines returned to the tool output prefixed with filename and line number.

For the sake of sharing information, here are the details...

- Added a Tool that executes a Program, where the program is a batch file I created. I'm passing parameters $File and $BaseName.log and Capturing output.

Regular expression to match output (Posix is NOT checked under editor):

Code: Select all

^\([^:]+\):\([^:]+\)

File Register: 1
Line Register: 2
Contents of batch file:

Code: Select all

"C:\Program Files\SAS\SASFoundation\9.2(32-bit)\sas.exe" %1
findstr /N /I "error warning endsas converted values. uninitialized truncated repeats" %2*
Example Tool Output (double-clicking lines will take you to the log file):

Code: Select all

J:\Programs\QC>"C:\Program Files\SAS\SASFoundation\9.2(32-bit)\sas.exe" J:\Programs\QC\vd_dose.sas 

J:\Programs\QC>findstr /N /I "error warning endsas converted values. uninitialized truncated repeats" vd_dose.log* 
vd_dose.log:425:289        %put WARNING: Test Warning.;
vd_dose.log:426:WARNING: Test Warning.
vd_dose.log:432:NOTE: Variable THISX is uninitialized.
vd_dose.log:433:NOTE: Missing values were generated as a result of performing an operation on missing values.

Tool completed successfully
THANK YOU AGAIN!!!!
Post Reply