![]() |
|
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Hobbyist Programmer
Join Date: Jun 2005
Location: here
Posts: 137
Rep Power: 0
![]() |
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;
}
/*
* ...
*/
} |
|
|
|
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|