How to Solve PCSWS041 - The system has insufficient resources or the Script Engine is not properly installed

Hi All,

I am very new in PCOMM VB script and facing the below issue  which is creating obstacle to promote my code in  production...

I am invoking the below program(logcapture.mac) in a AS400 system after logging in to the main screen. It is running properly approx 36 Hrs and after that suddenly
getting stopped. Getting below error if trying to re-initiate from the same screen/session.

"PCSWS041 - The system has insufficient resources or the Script Engine is not properly installed"

But able  to re-initiate if I run with a fresh session by closing the previous.

	[PCOMM SCRIPT HEADER]
LANGUAGE=VBSCRIPT
DESCRIPTION=  ** TLPV - Log Capture v1.0 **
[PCOMM SCRIPT SOURCE]
OPTION EXPLICIT



Dim Logger, Domain_Id, atm_LoginID, atm_LoginPassword
Logger="ON"

'Domaid_ID =============>

Domain_Id = "xxxxxxx.xxxx_xxx"
atm_LoginID = "xxxxxxx"
atm_LoginPassword = "xxxxxxxxx"

'========================================================================================================================:


autECLSession.SetConnectionByName(ThisSessionName)

Dim Record_Low, Previous_Record_High, Record_High, Nw_Record_Low, Sub_System, Library, Current_ZNL, Pre_Library, Product, path, Node_Name, Nw_Node_Name, Iteration, s,nw_entry, filename,workpath, objFSO, RecordsFile, outFile, objFile,rAwdaTaU, rAwdaTaL,mystring,string_loop_count, k, Remaining_len, count, Logout_indicator
Logout_indicator="N"
Set objFSO=CreateObject("Scripting.FileSystemObject")
Main

Private sub Main()
	
Sub_System = "ATMVR"
Product="atm"	
Library = "BSID1580NP"
Case "NFSSBS"

				autECLSession.autECLPS.SendKeys ("SL " + Sub_System + "[eraseeof]"), 20, 7
				SendKeys("[enter]")
				autECLSession.autECLPS.SendKeys "addlible newlogpgm" + "[eraseeof]", 20, 7
				SendKeys("[enter]")
				autECLSession.autECLPS.SendKeys "addlible logmap" + "[eraseeof]", 20, 7
				SendKeys("[enter]")
				autECLSession.autECLPS.SendKeys "addlible " + Sub_System + "[eraseeof]", 20, 7	
				SendKeys("[enter]")
				autECLSession.autECLPS.SendKeys "ml" + "[eraseeof]", 20, 7
				SendKeys("[enter]")
				autECLSession.autECLPS.SendKeys "[pf10]"
				SendKeys("[enter]")
				if (Record_Low="") Then
					Record_Low  = autECLSession.autECLPS.GetText(2,67,InStr(autECLSession.autECLPS.GetText(2,67,10),"/")-1)
				else
					autECLSession.autECLPS.SendKeys Record_Low + "[eraseeof]", 2, 11
					SendKeys("[enter]")
				End If

call Initialise()

	Do
		Record_High  = autECLSession.autECLPS.GetText(2,67,InStr(autECLSession.autECLPS.GetText(2,67,10),"/")-1)

		if ((Record_High > Record_Low) or (len(Record_High)>len(Record_Low))) then
				Call record_fetch()
		else
			call Handle_logout()
			autECLSession.autECLPS.Wait(2000)
			autECLSession.autECLPS.SendKeys "+1" + "[eraseeof]", 2, 11
			SendKeys("[enter]")
		End If
	
	Loop While (True)
		call wait_Sub
end sub


Private Function record_fetch()
		
		nw_entry=0
		
		outFile = "D:\atm Data\work\Logs_Output_" + Replace(Replace(Replace(Now(),":",""),"-","")," ","") + "_"+ Product +".txt"
		workpath="D:\atm Data\work"
		path = "D:\atm Data\"
		filename=Replace(outFile,workpath,"")
		Set objFile = objFSO.CreateTextFile(outFile,True)
		call wait_Sub
		Iteration=0
		Do while (Iteration < 8)
		
			-------------few lins  of operation----------------
			-------------few lins  of operation----------------
			-------------few lins  of operation----------------
			-------------few lins  of operation----------------
								'===========================Data Write in File==================================================================
								objFile.WriteLine(CStr(len(rAwdaTaU + rAwdaTaL)) + ":" + Replace(Current_ZNL," ","") + ":" + Replace(Record_Low," ","") + ":" + Mid(Node_Name,32,3) + ":" + Mid(Node_Name,31,1) + ":" + Mid(Node_Name,1,6) + ":" + Mid(Node_Name,7,9)+ ":" + mystring)
								call wait_Sub
								'===============================================================================================================
			-------------few lins  of operation----------------
			-------------few lins  of operation----------------
			-------------few lins  of operation----------------			

						End If
					End If
				End If
			Iteration=Iteration + 1


			End If	
			autECLSession.autECLPS.SendKeys "W207" + "[eraseeof]", 2, 11
			SendKeys("[enter]")
			
			End If					
			autECLSession.autECLPS.SendKeys "+1" + "[eraseeof]", 2, 11
			SendKeys("[enter]")
			Record_High  = autECLSession.autECLPS.GetText(2,67,InStr(autECLSession.autECLPS.GetText(2,67,10),"/")-1)
		Loop		
		objFile.Close
		Set objFile=Nothing
		call wait_Sub
		If (objFSO.FileExists(path+filename)) Then
			objFSO.MoveFile workpath & filename, workpath & filename+"_2.txt"
			call wait_Sub
			objFSO.MoveFile workpath & filename+"_2.txt","D:\atm Data\"
		Else
			objFSO.MoveFile workpath & filename,"D:\atm Data\"
		End If
		call wait_Sub
		
End Function


Private sub wait_Sub()
	autECLSession.autECLOIA.WaitForAppAvailable
	autECLSession.autECLOIA.WaitForInputReady
end sub


Private function SendKeys(value)
	call wait_Sub
	autECLSession.autECLPS.SendKeys value
	call wait_Sub
end function


Private function Raw_data_fetch()
		
		rAwdaTaU=""
		rAwdaTaL=""
		Remaining_len=""
		count = 1
		Do
			autECLSession.autECLPS.Wait(200)
			rAwdaTaU = rAwdaTaU + autECLSession.autECLPS.GetText(7,2,78)
			call wait_Sub
			rAwdaTaL = rAwdaTaL + autECLSession.autECLPS.GetText(8,2,78)
			call wait_Sub
			If(autECLSession.autECLPS.GetText(7,79,1) = "4" AND autECLSession.autECLPS.GetText(8,79,1) = "0") Then
				Exit Do
			End If
			Handle_logout()
			If Logout_indicator="Y" Then
				Logout_indicator="N"
				exit function
			End If	
			autECLSession.autECLPS.SendKeys "[pf20]"
				call wait_Sub
			count = count + 1
		Loop While (count < 19)
		'==========================Data Prepare For Write===========================================================
						
						If(len(rAwdaTaU + rAwdaTaL)<=1024) Then
								string_loop_count = 1
						ElseIf(len(rAwdaTaU + rAwdaTaL)>1024 AND len(rAwdaTaU + rAwdaTaL)<=2048) Then
								string_loop_count = 2
						Else
								string_loop_count = 3
						End If

						Remaining_len = len(rAwdaTaU + rAwdaTaL)
								mystring="" 

						For k = 1 To string_loop_count
							If(Remaining_len > 1024) Then
								mystring=mystring +  Mid((rAwdaTaU + rAwdaTaL), (1024 * (k-1)) + 1, 1024)
							Else
								mystring=mystring +  Mid((rAwdaTaU + rAwdaTaL), (1024 * (k-1)) + 1, 1024)
							End If
							Remaining_len = Remaining_len - 1024
						Next
end function

Open in new window


Till this point my assumption is the code " Set objFile = objFSO.CreateTextFile(outFile,True)" in record_fetch() function occupying some memory in an
repitative fashion as the function is being called infinitely which is not being freed even after execution of  "Set objFile=Nothing" till the session is
alive.
I will be very much thankful if some one guide/put some light on this.


Thanks
Indrajit DharaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gary PattersonVP Technology / Senior Consultant Commented:
Try deallocating objFSO as well as objFile.  You can verify that the error is due to a memory leak by monitoring the memory used by the process in Task Manager or SysInternals Process Monitor.
Indrajit DharaAuthor Commented:
Thanks Gary for your comment.

Yes I have verified the memory leak by monitoring at windows  Task Manager and been confirmed about that leak.
But My incompetence is to tackle that situation.

I have tried by Set objFile=Nothing to de-allocate the memory but that is not working  in this infinite run, after  36 Hrs(approx) run it is being stopped and when I am re-initiating from the same session/screen it is throwing above error message.
Now what I think is
1. Is that memory not being freed unless program come out from the existing session? If it is so then is there any in-built function in PCOMM
     VBS to run-time de-allocate so that physical memory can be reused in the same session?
2. Or is there any other way to handle these scenario so that automatic program termination can be  avoid?
3. Is there any way to initiate new session during a function call which I am doing  at my above code?

Please suggest/guide.  

Thanks
Gary PattersonVP Technology / Senior Consultant Commented:
Before you spend a lot of time debugging your script, you may want to ensure that you're running the latest version of PCOMM, with the latest service packs applied.  In the past, there have been memory leaks within PCOMM itself that could cause this to happen.

I have tried by Set objFile=Nothing to de-allocate the memory but that is not working  in this infinite run, after  36 Hrs(approx) run it is being stopped and when I am re-initiating from the same session/screen it is throwing above error message.

Suggest you deallocate every variable after you are done with it before going back to make another pass through the code, especially  

You can also dump the process and use windbg to help find the problem object:

https://blogs.msdn.microsoft.com/alikl/2009/02/15/identifying-memory-leak-with-process-explorer-and-windbg/

Now what I think is
1. Is that memory not being freed unless program come out from the existing session? If it is so then is there any in-built function in PCOMM
     VBS to run-time de-allocate so that physical memory can be reused in the same session?

If all else fails, shutting down the script and restarting it occasionally may be a practical solution.  

2. Or is there any other way to handle these scenario so that automatic program termination can be  avoid?

Find and fix the memory leak, or shut down the script and re-start it from time to time are the only options I can think of.

3. Is there any way to initiate new session during a function call which I am doing  at my above code?

Open in new window


Not sure.  I don't know how you are starting this script in the first place, and how it interacts with your applications.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

Indrajit DharaAuthor Commented:
Thank you very much Gary for your valuable inputs.

1. Regarding PCOMM VBS version which is installed currently:

      PCOMM iSeries Access for Windows
      WorkStation Program Version 6.0 for Windows
       20091005 S

2. Installation for windbg --- I need to take approval from INFRA team which I belief it will take time because of admin cred and all.
                                           Although I have already requested for that.

3. For immediate work around I am exactly trying the same which you are suggesting, like to initiate duplicate session repetitively after a certain interval and stop execution       after 8 Hrs run before re-initiate another duplicate session so that the memory can be de-allocated.  This loop should be controlled from the outside of this main program.
      I am trying to make it through a batch program.
      Currently I am starting the above script by executing below commands in CMD prompt.
      
      "C:\Program Files (x86)\IBM\ClientAccess\pcsw.exe"  C:\Users\<user_id>\Desktop\ATM.ws      /M=LogCaptureV1.0.mac

I will surely get back to you if I able to use the  debug  tool after install in my client m/c  and find any culprit variable/object for that memory leak behavior.

Thanks a lot again Gary for your immediate attention and suggestions.
Gary PattersonVP Technology / Senior Consultant Commented:
PCOMM iSeries Access for Windows
      WorkStation Program Version 6.0 for Windows
       20091005 S

Not sure what version of IBM i Access for Windows you are running, but that 20091005 version number makes me think you are running fairly old code.  (I'm running IBM i Access for Windows V7R1, Service Pack SI64724, and the version on my PCOMM is 20170413 S).

I suggest you upgrade to IBM i Access For Windows V7R1, if you aren't already on that version, and apply the latest IBM i Access for Windows service pack.  If you can't upgrade for some reason, at least install the latest service pack for your version.

https://www-03.ibm.com/systems/power/software/i/access/windows/sp_history.html

Getting the latest code could possibly solve your problem, or maybe prevent a future one.
Indrajit DharaAuthor Commented:
Hi Gary,

I apologize for this delay response since I was busy for the promotion in production.

Regarding the status of my sought help here :
1. Currently my client has agreed to stop this program during off business  hour and start again when business start,  since from business perspective off business hours data is less important.
Although I have asked for a upgrade with latest IBM i Access for Windows service pack which they will probably do after this sprint.
due to that I have no proven result  of that solution and  have to wait for any further R&D.
I will surely update you if I have any positive outcome from this which I faced as a bottleneck.

2. Secondly I have prepared  ready another supporting script which  will be shutting down the main script/program and restarting it occasionally which was also suggested by you.  It seems more practical solution at this moment and I will try to  implement in later if the upgrade fails to solve the issue.

Thank you very much for your immense support and help again.

Indrajit
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.