Solved

memory problem with shell

Posted on 1998-11-09
3
155 Views
Last Modified: 2010-04-30
Using VB4, I shell to a program lots of times, this works successfully but each time I loop round the shell I seem to lose a bit of memory (about 1k bytes). After about 200 times round the loop the program crashes with a memory problem. I close all files properly and can see the memory being eaten up by means of the GetFreeSpace function. What can I do to make my program run forever ?
0
Comment
Question by:cjf
3 Comments
 

Expert Comment

by:cmihalache
Comment Utility
When you shell a program, this call dosn't wait until your new process is finished. After 200 shells, you can have 200 instances of your shelled program in the memory. If this is the problem, I can tell you what to do to solve it.
0
 
LVL 3

Accepted Solution

by:
vikiing earned 100 total points
Comment Utility
SHELL command triggers a "child" process, but it does NOT wait process completion, that is, while second process is running, control goes back to VB to continue it's job.

You can do the following:
a) The process triggered thru SHELL statement must create, upon completion, a unique file (no matter be its contents), let's say, DUMMY.DAT

b) VB program, in order "to wait" process to end, can do:

     Do
          Shell  'Here, upon completion
                 'SHELLed process created DUMMY.DAT
          On Error Resume Next
          Do
             Open "DUMMY.DAT" for input as #99
          Loop while Err<>0
          Close #99 : Kill "DUMMY.DAT"
     Loop

That stuff synchronizes execution of SHELLed process, waiting until it completes before starting a new instance of a SHELL

(Yes, I know it's horrible; but it's the only way I can invent now... :)
0
 
LVL 12

Expert Comment

by:mark2150
Comment Utility
There is also the ExecCmd method (I don't know if this works under VB4 or not). This version waits for the child to complete before continuing and will prevent your parent from launching a whole bunch of child tasks.

M

0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now