Solved

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

Posted on 2004-09-16
14
346 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
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 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 20 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

734 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