Solved

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

Posted on 2004-09-16
14
333 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
 
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
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…

705 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now