Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2004-09-16
14
Medium Priority
?
356 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
  • 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
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!

 
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

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

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. …
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand column That will then direct you to their download page. From that p…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
Suggested Courses

926 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