Solved

_spawnlp returns E2BIG

Posted on 1998-06-17
8
456 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
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.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
Suggested Courses

710 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