ErrorLevel Command Required?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: ErrorLevel Command Required?

#16 Post by foxidrive » 18 May 2012 21:28

Try this:

Code: Select all

set "mFinURL=%mURL1%%%G%mURL2%%%G%mURL3%"

for /f "delims=" %%G in (id.txt) do (
wget --http-user=%IMSUSER% --http-password=%IMSPASS% --tries=10 -O - >> C:\Users\MatthewM.MEDICAGROUP\Desktop\UnreportorAssignBatch\%ims% %mFinURL%
)

CLS

set "mFinSPS=%mURL1%%%b%mURL2%%%b%mURL4%%%b%mURL5%%%c"
rem This opens the IMS and logs in
::start OpenIMS.exe
ping localhost -n 10 > nul

rem This reads the accession numbers in acc.txt searches ims.txt and outputs the id to variable %%a and spsid to variable %%c
for /f "delims=" %%a in ('type "acc.txt"') do (
for %%z in ('sed -n "s/.*&sps_id=[0-9][0-9][0-9][0-9][0-9][0-9][0-9]');.><td>%%a.*<td>\(.*\)<\/td>.*<\/td>.*/\1/p" "ims.txt"') do (
for /f "tokens=1,2" %%b in ('sed -n "s/.*=\(.*\)&sps_id=\([0-9][0-9][0-9][0-9][0-9][0-9][0-9]\)');.><td>%%a.*/\1 \2/p" "ims.txt"') do (

echo the reference "%%a" returns ID="%%b" and number "%%c"
if "%%z"=="Unreported" echo and Unreported was found

start chrome.exe %mFinSPS%
ping localhost -n 6 > nul
rem This runs a AHK script which unreports the exams on the IMS
if not "%%z"=="Unreported" start ChangeToKT.exe
ping localhost -n 6 > nul
)
)
)

Matt20687
Posts: 54
Joined: 02 May 2012 14:42

Re: ErrorLevel Command Required?

#17 Post by Matt20687 » 21 May 2012 05:24

foxidrive wrote:Try this:

Code: Select all

set "mFinURL=%mURL1%%%G%mURL2%%%G%mURL3%"

for /f "delims=" %%G in (id.txt) do (
wget --http-user=%IMSUSER% --http-password=%IMSPASS% --tries=10 -O - >> C:\Users\MatthewM.MEDICAGROUP\Desktop\UnreportorAssignBatch\%ims% %mFinURL%
)

CLS

set "mFinSPS=%mURL1%%%b%mURL2%%%b%mURL4%%%b%mURL5%%%c"
rem This opens the IMS and logs in
::start OpenIMS.exe
ping localhost -n 10 > nul

rem This reads the accession numbers in acc.txt searches ims.txt and outputs the id to variable %%a and spsid to variable %%c
for /f "delims=" %%a in ('type "acc.txt"') do (
for %%z in ('sed -n "s/.*&sps_id=[0-9][0-9][0-9][0-9][0-9][0-9][0-9]');.><td>%%a.*<td>\(.*\)<\/td>.*<\/td>.*/\1/p" "ims.txt"') do (
for /f "tokens=1,2" %%b in ('sed -n "s/.*=\(.*\)&sps_id=\([0-9][0-9][0-9][0-9][0-9][0-9][0-9]\)');.><td>%%a.*/\1 \2/p" "ims.txt"') do (

echo the reference "%%a" returns ID="%%b" and number "%%c"
if "%%z"=="Unreported" echo and Unreported was found

start chrome.exe %mFinSPS%
ping localhost -n 6 > nul
rem This runs a AHK script which unreports the exams on the IMS
if not "%%z"=="Unreported" start ChangeToKT.exe
ping localhost -n 6 > nul
)
)
)



Hello,

This does not appear to be working, it is not finding the word "Unreported" and carrying on running the exe.

Thanks,
Matt

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: ErrorLevel Command Required?

#18 Post by foxidrive » 21 May 2012 05:32

edited by mistake
Last edited by foxidrive on 21 May 2012 06:55, edited 2 times in total.

Matt20687
Posts: 54
Joined: 02 May 2012 14:42

Re: ErrorLevel Command Required?

#19 Post by Matt20687 » 21 May 2012 06:17

Hell foxi,

It echos:

the extra line reports "'sed"

Just incase you miss it from the above, it is " 'sed"

Thanks,
Matt

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: ErrorLevel Command Required?

#20 Post by foxidrive » 21 May 2012 06:55

Thanks. That tells me where the error is - I left /f off the for command. Try this

Code: Select all

set "mFinURL=%mURL1%%%G%mURL2%%%G%mURL3%"

for /f "delims=" %%G in (id.txt) do (
wget --http-user=%IMSUSER% --http-password=%IMSPASS% --tries=10 -O - >> C:\Users\MatthewM.MEDICAGROUP\Desktop\UnreportorAssignBatch\%ims% %mFinURL%
)

CLS

set "mFinSPS=%mURL1%%%b%mURL2%%%b%mURL4%%%b%mURL5%%%c"
rem This opens the IMS and logs in
::start OpenIMS.exe
ping localhost -n 10 > nul

rem This reads the accession numbers in acc.txt searches ims.txt and outputs the id to variable %%a and spsid to variable %%c
for /f "delims=" %%a in ('type "acc.txt"') do (
for /f "delims=" %%z in ('sed -n "s/.*&sps_id=[0-9][0-9][0-9][0-9][0-9][0-9][0-9]');.><td>%%a.*<td>\(.*\)<\/td>.*<\/td>.*/\1/p" "ims.txt"') do (
for /f "tokens=1,2" %%b in ('sed -n "s/.*=\(.*\)&sps_id=\([0-9][0-9][0-9][0-9][0-9][0-9][0-9]\)');.><td>%%a.*/\1 \2/p" "ims.txt"') do (

echo the reference "%%a" returns ID="%%b" and number "%%c"

if "%%z"=="Unreported" echo and Unreported was found

start chrome.exe %mFinSPS%
ping localhost -n 6 > nul
rem This runs a AHK script which unreports the exams on the IMS
if not "%%z"=="Unreported" start ChangeToKT.exe
ping localhost -n 6 > nul
)
)
)

Matt20687
Posts: 54
Joined: 02 May 2012 14:42

Re: ErrorLevel Command Required?

#21 Post by Matt20687 » 21 May 2012 07:58

Hello Foxi,

Works well on the first ID, when it moves onto the next it doesnt work. Here is the text it will be referring to when looking for %%z.

</script><h2>Booking Management</h2><b>Procedures for </b><br><b>%%b</b><p><table class="infotab" cellpadding="4" cellspacing="1"><tr><th>Procedure ID</th><th>Scheduled Date</th><th>Procedure Code</th><th>Procedure Room</th><th>Modality</th><th>Consultant</th><th>Requester</th><th>Referrer</th><th>Report State</th><th>Images</th></tr><tr class="c1" onClick="ii0('op=editexam&patient_id=%%b&sps_id=1234567');"><td>ABC1234</td><td>Jan 10 2012 12:00AM</td><td>R FEMUR</td><td></td><td>CR</td><td>KT</td><td> </td><td></td><td>Unreported</td><td>1</td></tr><tr class="c2" onClick="ii0('op=editexam&patient_id=%%b&sps_id=2345678');"><td>BCD1234</td><td>Mar 30 2012 1:54PM</td><td>CT CT Sinuses</td><td></td><td>CT</td><td>DNR</td><td> </td><td></td><td>Do not report</td><td>335</td></tr></table><p>Click on a row to select that procedure.<p><input type="button" value="Make New Booking" onClick="location.href='/booking.php?op=newexam&patient_id=%%b';"><p><input type="button" value="Back To Patient" onClick="location.href='/booking.php?op=querypatid&patient_id=%%b';"> <input type="button" value="New Query" onClick="location.href='/booking.php';"></center></body></html>

Is it a problem with the search criteria? There are many <td> and </td> so do you think it is getting confused?

Thanks,
Matt

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: ErrorLevel Command Required?

#22 Post by foxidrive » 21 May 2012 17:11

Yes, it is confused Matt. There needs to be a common entry that sed can use to limit the search. Regular expressions using SED are classed as 'greedy' and it will search to the LAST match in the string and not the NEXT match, unless there is some text that can anchor sed to an entry.

I think it is also time to consider that whenever someone changes the web page then this type of parsing of HTML using SED is going to break, and be difficult for you to fix.

You can still use batch files but I think the way to go is to download the web page as you are doing and then run it through a HTML to TEXT converter, and then use batch files to parse the text information. The text would be similar to what you would have when you use the SAVE AS text option in a web browser, or a text converter can add delimiters also.

HTMstrip by Bruce Guthrie is a rather dated free MSDOS command line tool but is limited to short filenames. There may be better modern tools.

Try this on the web page and see if it gives you the information you need - the format can be changed.

Code: Select all

htmstrip /border=t page.htm

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: ErrorLevel Command Required?

#23 Post by foxidrive » 21 May 2012 23:02

So a way around this problem with "Unreported" might be in the following (untested):

It uses HTMSTRIP and converts the IMS.TXT before the loop starts, then before ChangeToKT.exe runs it checks for the current %%a entry line and sees if "Unreported" is in the line and it will launch ChangeToKT.exe if it is not found.

Code: Select all

set "mFinURL=%mURL1%%%G%mURL2%%%G%mURL3%"

for /f "delims=" %%G in (id.txt) do (
wget --http-user=%IMSUSER% --http-password=%IMSPASS% --tries=10 -O - >> C:\Users\MatthewM.MEDICAGROUP\Desktop\UnreportorAssignBatch\%ims% %mFinURL%
)

CLS

set "mFinSPS=%mURL1%%%b%mURL2%%%b%mURL4%%%b%mURL5%%%c"
rem This opens the IMS and logs in
::start OpenIMS.exe
ping localhost -n 10 > nul

htmstrip /border=t ims.txt

rem This reads the accession numbers in acc.txt searches ims.txt and outputs the id to variable %%a and spsid to variable %%c
for /f "delims=" %%a in ('type "acc.txt"') do (
for /f "tokens=1,2" %%b in ('sed -n "s/.*=\(.*\)&sps_id=\([0-9][0-9][0-9][0-9][0-9][0-9][0-9]\)');.><td>%%a.*/\1 \2/p" "ims.txt"') do (

echo the reference "%%a" returns ID="%%b" and number "%%c"

start chrome.exe %mFinSPS%
ping localhost -n 6 > nul
rem This runs a AHK script which unreports the exams on the IMS
find "| %%a " <ims.out |find "Unreported">nul || start ChangeToKT.exe
ping localhost -n 6 > nul
)
)
del ims.out

Matt20687
Posts: 54
Joined: 02 May 2012 14:42

Re: ErrorLevel Command Required?

#24 Post by Matt20687 » 22 May 2012 00:33

Hello Foxi,

Bit of a pain, it seems HTMSTRIP only works on 32 bit. I cannot seem to find a 64 bit version anywhere, are you aware of any 64 versions?

Thanks,
Matt

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: ErrorLevel Command Required?

#25 Post by foxidrive » 22 May 2012 02:41

Download this tool and try the following.

http://www.nirsoft.net/utils/htmlastext.html


Code: Select all

set "mFinURL=%mURL1%%%G%mURL2%%%G%mURL3%"

for /f "delims=" %%G in (id.txt) do (
wget --http-user=%IMSUSER% --http-password=%IMSPASS% --tries=10 -O - >> C:\Users\MatthewM.MEDICAGROUP\Desktop\UnreportorAssignBatch\%ims% %mFinURL%
)

CLS

set "mFinSPS=%mURL1%%%b%mURL2%%%b%mURL4%%%b%mURL5%%%c"
rem This opens the IMS and logs in
::start OpenIMS.exe
ping localhost -n 10 > nul

(
echo [Config]
echo OpenInNotepad=0
echo CharsPerLine=75
echo Source=ims.txt
echo Dest=ims.out
echo SkipTitleText=0
echo AddLineUnderHeader=0
echo SkipTableHeaderText=0
echo TableCellDelimit=2
echo HeadingLineChars=======
echo HorRuleChar==
echo ListChars=*o-@#
echo ConvertMode=1
echo AllowCenterText=0
echo AllowRightText=0
echo DLSpc=8
echo LinksDisplayFormat=%T
echo EncloseBoldCharsStart=^<^<
echo EncloseBoldCharsEnd=^>^>
echo EncloseBold=0
echo SubFolders=0
) >ims.cfg

HtmlAsText.exe /run "%cd%\ims.cfg"


rem This reads the accession numbers in acc.txt searches ims.txt and outputs the id to variable %%a and spsid to variable %%c
for /f "delims=" %%a in ('type "acc.txt"') do (
for /f "tokens=1,2" %%b in ('sed -n "s/.*=\(.*\)&sps_id=\([0-9][0-9][0-9][0-9][0-9][0-9][0-9]\)');.><td>%%a.*/\1 \2/p" "ims.txt"') do (

echo the reference "%%a" returns ID="%%b" and number "%%c"

start chrome.exe %mFinSPS%
ping localhost -n 6 > nul
rem This runs a AHK script which unreports the exams on the IMS
findstr "^%%a," ims.out |find "Unreported">nul || start ChangeToKT.exe
ping localhost -n 6 > nul
)
)
del ims.out
del ims.cfg

Matt20687
Posts: 54
Joined: 02 May 2012 14:42

Re: ErrorLevel Command Required?

#26 Post by Matt20687 » 22 May 2012 05:14

foxidrive wrote:Download this tool and try the following.

http://www.nirsoft.net/utils/htmlastext.html


Code: Select all

set "mFinURL=%mURL1%%%G%mURL2%%%G%mURL3%"

for /f "delims=" %%G in (id.txt) do (
wget --http-user=%IMSUSER% --http-password=%IMSPASS% --tries=10 -O - >> C:\Users\MatthewM.MEDICAGROUP\Desktop\UnreportorAssignBatch\%ims% %mFinURL%
)

CLS

set "mFinSPS=%mURL1%%%b%mURL2%%%b%mURL4%%%b%mURL5%%%c"
rem This opens the IMS and logs in
::start OpenIMS.exe
ping localhost -n 10 > nul

(
echo [Config]
echo OpenInNotepad=0
echo CharsPerLine=75
echo Source=ims.txt
echo Dest=ims.out
echo SkipTitleText=0
echo AddLineUnderHeader=0
echo SkipTableHeaderText=0
echo TableCellDelimit=2
echo HeadingLineChars=======
echo HorRuleChar==
echo ListChars=*o-@#
echo ConvertMode=1
echo AllowCenterText=0
echo AllowRightText=0
echo DLSpc=8
echo LinksDisplayFormat=%T
echo EncloseBoldCharsStart=^<^<
echo EncloseBoldCharsEnd=^>^>
echo EncloseBold=0
echo SubFolders=0
) >ims.cfg

HtmlAsText.exe /run "%cd%\ims.cfg"


rem This reads the accession numbers in acc.txt searches ims.txt and outputs the id to variable %%a and spsid to variable %%c
for /f "delims=" %%a in ('type "acc.txt"') do (
for /f "tokens=1,2" %%b in ('sed -n "s/.*=\(.*\)&sps_id=\([0-9][0-9][0-9][0-9][0-9][0-9][0-9]\)');.><td>%%a.*/\1 \2/p" "ims.txt"') do (

echo the reference "%%a" returns ID="%%b" and number "%%c"

start chrome.exe %mFinSPS%
ping localhost -n 6 > nul
rem This runs a AHK script which unreports the exams on the IMS
findstr "^%%a," ims.out |find "Unreported">nul || start ChangeToKT.exe
ping localhost -n 6 > nul
)
)
del ims.out
del ims.cfg


Works perfectly, thanks :) Little question, how is it you have so much knowledge on all of this??

Do you know much about Auto Hot Key?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: ErrorLevel Command Required?

#27 Post by foxidrive » 22 May 2012 05:47

Glad it works. I've never used auto hot key...

Post Reply