Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to get around C++ "system( )" parameter length limitation!!! (128 char)

Posted on 2004-09-16
14
Medium Priority
?
352 Views
Last Modified: 2013-11-17
I am transfering my batch file code to C++ but encounter the limitation. How do I get around it?
My guess is, it is because C++ treat the parameter as unicode else the limitation should be 256

0
Comment
Question by:weicheun
[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
  • 6
  • 6
14 Comments
 

Author Comment

by:weicheun
ID: 12081894
but someone told me that it Has nothing to do with C++ the language; it has to do with your c library and how it's executing the command.
0
 
LVL 13

Expert Comment

by:SteH
ID: 12082090
Have you checked the return value of the call to system? In case of -1 check errno if it is E2BIG. In that case you hit a OS liimitation rather than a C++ limitation.

Why should the parameter length be limited to 256 chars if not UNICODE? A c-style string terminates on the first char == '0x00'; no length is specified in the variable itself. So from formal analysis there doesn't need to be any limitation (except page sizes perhaps).
0
 

Author Comment

by:weicheun
ID: 12082337
if (errno==TEXT("E2BIG"))
{
   MessageBox(NULL,TEXT("E2BIG"),TEXT("E2BIG"),MB_OK );  
}

does not work    
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 13

Expert Comment

by:SteH
ID: 12082392
E2BIG is a integer constant defined in errno.h. So you need to add
#include <errno.h>

and next the comparison should be:

int iRet = system ("what ever you need to put here");
if (-1 == iRet) {
   if (E2BIG == errno) {
      // snip
   }
}
0
 

Author Comment

by:weicheun
ID: 12098703
iRet is -1
but it is not E2BIG.
so what could it be?
0
 
LVL 13

Expert Comment

by:SteH
ID: 12100179
Have a look at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_system.2c_._wsystem.asp
If the return value of the call to system is -1 you should check the global variable errno.
0
 

Author Comment

by:weicheun
ID: 12110405
Great. It is "EACCES" error and according to the page
System error message is "Permission denied".

but what does it mean and is there a way to resolve it?
0
 
LVL 13

Expert Comment

by:SteH
ID: 12110445
This means that program can't access the file in question. It could be not enough privileges or the attributes state this file as not being executable. On what system are you running and as what user?

Can you post the line with the system command please.
0
 

Author Comment

by:weicheun
ID: 12130768
I use winrar to zip 7 file this is the code:

system("\"C:\\Program Files\\WinRAR\\rar.exe\" a -sfx -t -m5 -df -ep -ag+YYYYMMDD -- \"C:\\backup\\ 7Pamora\" \"C:\\WINDOWS\\TEMP\\fn.dmp\" \"C:\\WINDOWS\\TEMP\\fa.dmp\" \"C:\\WINDOWS\\TEMP\\hr.dmp\" \"C:\\WINDOWS\\TEMP\\loan.dmp\" \"C:\\WINDOWS\\TEMP\\s.dmp\" \"C:\\WINDOWS\\TEMP\\resit.dmp\" \"C:\\WINDOWS\\TEMP\\sys.dmp\"");
0
 
LVL 13

Expert Comment

by:SteH
ID: 12130791
Do you and the app have enough rights to execute rar.exe? Can "C:\backup\ 7Pamora" be written (Should there be a space at the beginning of the file name?)?
0
 

Author Comment

by:weicheun
ID: 12326286
i am able to use this code it if i reduce the number of file to be compress.
0
 
LVL 13

Accepted Solution

by:
SteH earned 80 total points
ID: 12336808
And can you use it for all files? If you reduce the number of files you might drop the one which gives you an access error.

Another option I see is to add one file after the other. That is one system (xx) call per file.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

688 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