| Author |
Message |
|
Matt20687
Joined: 02 May 2012 14:42 Posts: 54
|
 ErrorLevel Command Required?
Hello, I wonder if anyone can help? I would like to have a error level (i think) for the below code, basically what i would like to do is run the below code if the word Unreported occurs in ims.txt. If the word Unreported does not occur in ims.txt i would like it to go back to MENU. Originally i thought i could do a simple ERRORLEVEL command but i cannot seem to get it to work. I would provide you with my attempts but i mistakenly deleted them!!! Code: 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% )
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 start ChangeToKT.exe ping localhost -n 6 > nul ) )
del ims.txt goto MENU
|
| 14 May 2012 14:04 |
|
 |
|
abc0502
Joined: 26 Oct 2011 22:38 Posts: 1006 Location: Egypt
|
 Re: ErrorLevel Command Required?
u didn't provide the whole code so : What is ur code (the code for searching for the word) generate when used in cmd window in both situation (when find and when not find) ?
Last edited by abc0502 on 14 May 2012 14:42, edited 1 time in total.
|
| 14 May 2012 14:40 |
|
 |
|
Fawers
Joined: 08 Apr 2012 17:11 Posts: 187
|
 Re: ErrorLevel Command Required?
A simple way to set errorlevel to any integer is using cmd /c exit n, where n is the desired number.
I just tried directly on my command line to set it to 4 - and it worked. You just have to put this piece of code where you need ERRORLEVEL to be changed at.
|
| 14 May 2012 14:41 |
|
 |
|
foxidrive
Joined: 10 Feb 2012 02:20 Posts: 2478
|
 Re: ErrorLevel Command Required?
The line at the top will make it go to :menu if "Unreported" does not exist in ims.txt Code: find "Unreported" <ims.txt>nul || goto :Menu
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% )
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 start ChangeToKT.exe ping localhost -n 6 > nul ) )
del ims.txt goto MENU
[/quote]
|
| 14 May 2012 17:06 |
|
 |
|
Matt20687
Joined: 02 May 2012 14:42 Posts: 54
|
 Re: ErrorLevel Command Required?
foxidrive wrote: The line at the top will make it go to :menu if "Unreported" does not exist in ims.txt Code: find "Unreported" <ims.txt>nul || goto :Menu
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% )
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"') [color=#FF0000]do (
echo the reference "%%a" returns ID="%%b" and number "%%c"
start chrome.exe %mFinSPS% ping localhost -n 6 > nul start ChangeToKT.exe ping localhost -n 6 > nul ) )[/color]
del ims.txt goto MENU
[/quote] Hello Foxi, The find needs to be within the loop highlighted in red above. So each time around it will search the IMS.txt looking for the string that has %%b in it and then: 1. If the word Unreported is there then to goto MENU 2. If the word Unreported is not there to carry on with the loop It will need to be before the code starts ChangetoKT.exe. I would assume it would look something similar to: 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"') [color=#FF0000]do ( echo the reference "%%a" returns ID="%%b" and number "%%c" start chrome.exe %mFinSPS% ping localhost -n 6 > nul find "Unreported" <ims.txt>nul || goto :Menu start ChangeToKT.exe ping localhost -n 6 > nul ) )
|
| 15 May 2012 06:16 |
|
 |
|
Squashman
Joined: 23 Dec 2011 13:59 Posts: 1002
|
 Re: ErrorLevel Command Required?
Why would you even want it to process for the loop if it is not in the IMS file?
|
| 15 May 2012 07:59 |
|
 |
|
Matt20687
Joined: 02 May 2012 14:42 Posts: 54
|
 Re: ErrorLevel Command Required?
Squashman wrote: Why would you even want it to process for the loop if it is not in the IMS file? If it is in the ims file the need for it to carry on is not required. If it is not in the ims file i need it to carry on with the loop. The reason for this is because if the loop carries on and it is already at the unreported status it will cause serious issues as the .exe file has a set amount of steps which manipulates the web page using autohotkey, this works well but I need to be able to ensure the script knows not to run the .exefile when the word unreported is within ims.txt. Again it needs to do a search for the id %%b and see if the word unreported exists, this was explained in my previous post.
|
| 15 May 2012 10:52 |
|
 |
|
Squashman
Joined: 23 Dec 2011 13:59 Posts: 1002
|
 Re: ErrorLevel Command Required?
Then change the double || to a double && in Foxi's code.
|
| 15 May 2012 15:48 |
|
 |
|
foxidrive
Joined: 10 Feb 2012 02:20 Posts: 2478
|
 Re: ErrorLevel Command Required?
I'm unsure of your needs Matt but if you want to process the loop anyway, and only allow ChangeToKT.exe to run when unreported does not exist, then this will do that. Code: find "Unreported" <ims.txt>nul || start ChangeToKT.exe If you want to avoid the loop altogether when "Unreported" does exist, then Squashman's suggestion of changing the || to && in my original suggestion should work. You have said the exact opposite so I'm unsure which is what you need. Matt20687 wrote: If the word Unreported does not occur in ims.txt i would like it to go back to MENU.
|
| 15 May 2012 19:43 |
|
 |
|
Squashman
Joined: 23 Dec 2011 13:59 Posts: 1002
|
 Re: ErrorLevel Command Required?
I certainly agree with Foxidrive. You seem to be contradicting yourself. Matt20687 wrote: If the word Unreported does not occur in ims.txt i would like it to go back to MENU. Matt20687 wrote: If it is not in the ims file i need it to carry on with the loop.
|
| 16 May 2012 05:35 |
|
 |
|
Matt20687
Joined: 02 May 2012 14:42 Posts: 54
|
 Re: ErrorLevel Command Required?
Squashman wrote: I certainly agree with Foxidrive. You seem to be contradicting yourself. Matt20687 wrote: If the word Unreported does not occur in ims.txt i would like it to go back to MENU. Matt20687 wrote: If it is not in the ims file i need it to carry on with the loop. Sorry about the confusion!! The correct statement is if the word Unreported occurs in ims.txt then i would like it to skip starting the .exe and start the loop again for the next ID. So i would need to alter your code Foxi to replace || to &&? So it would look like: Code: 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 "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 "Unreported" <ims.txt>nul && start ChangeToKT.exe ping localhost -n 6 > nul ) ) Sorry again
|
| 16 May 2012 05:58 |
|
 |
|
foxidrive
Joined: 10 Feb 2012 02:20 Posts: 2478
|
 Re: ErrorLevel Command Required?
Matt20687 wrote: Sorry about the confusion!!
The correct statement is if the word Unreported occurs in ims.txt then i would like it to skip starting the .exe and start the loop again for the next ID. You need this line within the loop; Code: find "Unreported" <ims.txt>nul || start ChangeToKT.exe || means "If it can't find that word then run the exe file"
|
| 16 May 2012 18:55 |
|
 |
|
Matt20687
Joined: 02 May 2012 14:42 Posts: 54
|
 Re: ErrorLevel Command Required?
Hello,
This is not working exactly how i wanted. It is searching for the word 'Unreported' in ims.txt. Foxi i need to be able to search for the word Unreported which is on the same line as the variable %%c which is the sps_id in the sed command.
I do not know if it helps but the word unreported is laid out in the code as below.
<td>Unreported</td><td>53</td></tr><tr class="c2" onClick="ii0('op=editexam&patient_id=ID&sps_id=1234567
As you can see <td> is before the word Unreported and the closest unique identifier (sps_id) is a fair way away, is there any way to create a command that works within the sed loop that searches the ims.txt which returns the 3 different variables, do you remember creating this bit of code for me?
So to conclude i need a piece of code that will fit into and work within the sed loop and look at %%c which is the sps_id shown above and then look back to the left see if the word Unreported exists until it gets to <td>. If it does exist it is to not run the .exe, if it doesnt exist it is to run the .exe as stated in the previous posts.
|
| 18 May 2012 09:40 |
|
 |
|
foxidrive
Joined: 10 Feb 2012 02:20 Posts: 2478
|
 Re: ErrorLevel Command Required?
I'm unable to test this without the strings in ims.txt but this might work: Code: 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/<td>\(.*\)</td><td>.*&sps_id=[0-9][0-9][0-9][0-9][0-9][0-9][0-9]');.><td>%%a.*/\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 ) ) )
|
| 18 May 2012 10:04 |
|
 |
|
Matt20687
Joined: 02 May 2012 14:42 Posts: 54
|
 Re: ErrorLevel Command Required?
Hello,
Apologies the code was incorrect that i provided, i was look at a old version. The rules that i stated still apply but where the word Unreported lies is different. See below
</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=4892529');"><td>%%a</td><td>Dec 9 2011 12:00AM</td><td>MR BRAIN</td><td></td><td>MR</td><td>KT</td><td> </td><td></td><td>Unreported</td><td>187</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> // -->
So, the word Unreported is actually between %%a and </td>.
Does this help?
P.S. %%a is the booking number %%b is the ID and %%c is the SPS_ID
|
| 18 May 2012 10:24 |
|
|