Solved

_spawnlp returns E2BIG

Posted on 1998-06-17
8
452 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
Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

 
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

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…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

808 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