Solved

_spawnlp returns E2BIG

Posted on 1998-06-17
8
447 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

746 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