Solved

_spawnlp returns E2BIG

Posted on 1998-06-17
8
451 Views
Last Modified: 2008-02-01
I am writing a DOS program using MSVC 1.52, large memory model. The DOS program is running under W95.

I make a call, similar to:-

retval = _spawnlp(_P_WAIT, "notepad", "notepad", NULL);

retval returns -1
errno equals 7 (E2BIG)

This is likely because there is not enough memory to spawn the new process. If this *is* the problem, how do I free up memory in a DOS program to allow the _spawnlp to run.

This program has worked in the past on a different machine, I don't know what is different this time.
0
Comment
Question by:icd
8 Comments
 
LVL 3

Expert Comment

by:elfie
ID: 1251257
First try to find out what the available memory is just before the spawn function. Doe sit need to run in the same dos box, or is it possible to start it in another box?
0
 
LVL 11

Expert Comment

by:alexo
ID: 1251258
E2BIG means that the argument list is too long (no memory is ENOMEM).  Which is strange, since the call seems OK to me.  Hmmm...  Tried "notepad.exe"?
0
 
LVL 5

Author Comment

by:icd
ID: 1251259
As I understand it, a DOS program by default takes the maximum available (640k) memory. I am assuming that this is the reason why the 'notepad' (or any program in fact) cannot run.

The meaning of E2BIG is 'In MS-DOS, the argument list exceeds 18 bytes (not so), or the space required for the environment information exceeds 32K' (unlikely).

I see now that ENOMEM is the error I would expect if there were not enough memory, so what is going on?

0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 2

Expert Comment

by:kinkajou
ID: 1251260
You might want to try increasing your environment. Some of the steps I have taken to solve DOS memory problems are:

Add "SHELL=C:\COMMAND.COM C:\ /E:4096 /P" to CONFIG.SYS

Then I go to the process's icon in Windows and select properties and memory to adjust all of the memory settings to their maximum.
0
 
LVL 5

Author Comment

by:icd
ID: 1251261
kinkajou.

That solution was what I was hoping for, however it does not seem to have had any effect. I still get errno 7 (E2BIG).


0
 
LVL 1

Accepted Solution

by:
shivers earned 100 total points
ID: 1251262
I've been having this problem recently - I found it worked sporadically like that, but doing it like this seems to work fine:

if (spawnl(P_WAIT, "proggie.exe", NULL, NULL) == -1) {
  printf("Spawn Error!\n");
  exit(1);
};

(i.e. with a null instead of the second copy of the program name.  I'm not really sure why this should make a difference, but it works on mine ;)


0
 
LVL 5

Author Comment

by:icd
ID: 1251263
Shivers

Thanks for that reply. It was close enought to put me on the right track. The actual line I came up with in the end was:-

_spawnlp(_P_WAIT, "xcopy", "xcopy", "c:\\from", "c:\\to", NULL, NULL);

It is the two NULLs at the end that are significant, not the NULL for arg[0].

Thanks a lot.

0
 
LVL 11

Expert Comment

by:alexo
ID: 1251264
Doh!  Can anyone comment on that?  Requiring two NULLS seems like sheer stupidity.
0

Featured Post

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
In desperate need of help 8 136
C++ check and remove last word from a string 5 171
How to access ANSI/IEEE Std 754 or equivalent information ? 3 64
How to learn Linux? 10 61
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

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