Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Jun 15th, 2005, 7:36 PM   #1
L7Sqr
Hobbyist Programmer
 
Join Date: Jun 2005
Location: here
Posts: 137
Rep Power: 0 L7Sqr is an unknown quantity at this point
system () command in Borland C++ Bldr. 4

Here is what I am trying to do:
From a TMemo object I am pulling a line out (full path name) and chopping the string to the file name (a batch file). No problem.
From there I want to execute the batch file by means of a system () command. Each time I try this, I get a dos window open/shut and the system command returns an error (non-zero).
errno is supposed to be set accordingly, but when I check it, I get an invalid value. Valid values include: ENOENT, ENOEXEC, ENOMEM, none of which I get. When I check, the errno is set to "Error 0", which to me means, no error....
However, system returns non-zero when passed a NULL pointer (indicating that a command processor IS available) and returns 1 (which is not indicated as a possible return value) when I pass a valid command.
Anyone have a sugestion on where I might be going wrong?
I have tried copying the file to the cwd to avoid PATH issues, but to no avail.

So you can avoid the obvious:
- yes, it is a valid batch file (it runs when invoked seperately)
- yes, I parsed the string properly - its the first thing I checked.
- I have tried both the full path and just the file name - same results.

My windows experience is limited, so please bear with me.
Thanks in advance for the help.

the code snippet, in case it helps you...
while (frmMain->memList->Lines->Count != 0) {
   batch = frmMain->memList->Lines->Strings[0];
   pos = batch.LastDelimiter("\\") + 1;
   len = batch.Length () - pos;
   sub = batch.SubString (pos, len + 1);
   error = system (batch.c_str ());
   if (error) {
      if (errno == ENOENT) {
         msg = "Path not found";
      } else if (errno == ENOEXEC) {
         msg = "Exec format error";
      } else if (errno == ENOMEM) {
         msg = "No memory";
      } else {
         msg = "Unknown error: " + IntToStr(error);
      }
      MessageBoxA (frmMain->Handle, msg.c_str(), "Error msg", 0);
      frmMain->btnAddFile->Enabled = false;
      return;
   }
   /*
    * ...
    */
}
L7Sqr is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:14 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC