Solved

memory problem with shell

Posted on 1998-11-09
3
189 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
ID: 1443877
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
ID: 1443878
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
ID: 1443879
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

740 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