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

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

weicheunAsked:
Who is Participating?
 
SteHCommented:
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
 
weicheunAuthor Commented:
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
 
SteHCommented:
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
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
weicheunAuthor Commented:
if (errno==TEXT("E2BIG"))
{
   MessageBox(NULL,TEXT("E2BIG"),TEXT("E2BIG"),MB_OK );  
}

does not work    
0
 
SteHCommented:
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
 
weicheunAuthor Commented:
iRet is -1
but it is not E2BIG.
so what could it be?
0
 
SteHCommented:
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
 
weicheunAuthor Commented:
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
 
SteHCommented:
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
 
weicheunAuthor Commented:
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
 
SteHCommented:
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
 
weicheunAuthor Commented:
i am able to use this code it if i reduce the number of file to be compress.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.