![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Hobbyist Programmer
Join Date: Jun 2005
Location: here
Posts: 146
Rep Power: 4
![]() |
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;
}
/*
* ...
*/
} |
|
|
|
|
|
#2 |
|
PFO God In Training
![]() Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 599
Rep Power: 4
![]() |
with VC++ 6.0, I get 0 when the batch file is executed, and 1 if the batch file cannot be found (errno = 0, as you indicated). I think errno is 0 because the problem is not any of the indicated error numbers.
ShellExecute() may give you better errors. Last edited by Ancient Dragon; Jun 15th, 2005 at 10:31 PM. |
|
|
|
|
|
#3 |
|
Hobbyist Programmer
Join Date: Jun 2005
Location: here
Posts: 146
Rep Power: 4
![]() |
Yeah, I though of that as well, but the file (path included) is inserted into the memo object by way of an OpenFileDialog.....
I actually have the ReadOnly flag of the memo object set to true so a user wouldnt be able to change the text. Any other reason one can imagine I would get a 1 returned from the system command? Searching Borland's help files only mentions negative return on error and zero for success. (However, Borland simply calls Microsoft's built-in command, so I dont expect to find an extensive explanation). I'm retiring for the evening, but will search fresh in the morn... [edit] Oooh...Just caught the ShellExecute... I'll work with that tomorrow. Thanks![/edit] |
|
|
|
|
|
#4 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 893
Rep Power: 4
![]() |
Does the batch file name have a space in it? system() would then treat it as a command and a parameter.
|
|
|
|
|
|
#5 |
|
Hobbyist Programmer
Join Date: Jun 2005
Location: here
Posts: 146
Rep Power: 4
![]() |
I tried that for the copy...
pos = batch.LastDelimiter("\\") + 1;
len = batch.Length () - pos;
sub = batch.SubString (pos, len + 1);
cmd = "copy /Y \"" + batch + "\" " + sub;
/*
* double check the syntax
*/
if (debug)
frmMain->memList->Lines->Add (cmd);
error = system (cmd.c_str());
/*
*
*/With the same result... [edit] where cmd is the file ping_test.bat [/edit] Last edited by L7Sqr; Jun 16th, 2005 at 10:22 PM. |
|
|
|
|
|
#6 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 893
Rep Power: 4
![]() |
Can you zip up your project and attach it here? I have CBuilder 5, so I could try it on that.
|
|
|
|
|
|
#7 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
I have seen what you mean, so I guess it's possible, but it might be luck. I don't know how that would be done though.
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
|
|
|
|
|
#8 |
|
Newbie
Join Date: Nov 2004
Posts: 8
Rep Power: 0
![]() |
sup y'all
I came across this the other day at http://www.onecomputerguy.com/windowsxp_tips.htm To prevent applications from stealing the focus from the window you are working: Start Regedit Go to HKEY_CURRENT_USER \ Control Panel \ Desktop Edit the key ForegroundLockTimeout Give it a value of 00030d40 I have never had the need to use it, but I hope it works. |
|
|
|
|
|
#9 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 893
Rep Power: 4
![]() |
Here is a program you can call from your batch file to send the console window to the back of the Z order. I am not sure whether you will be able to compile it under Builder 4 as it uses GetConsoleWindow which is only available in Windows XP and 2000.
// SendToBack
// Send the current console window to the back
#define _WIN32_WINNT 0x0500
#include <windows.h>
int main(int argc, char *argv[])
{
HWND hWnd = GetConsoleWindow();
if (hWnd != NULL)
SetWindowPos(hWnd, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
return 0;
}If you can't get this going, you could try using the SetConsoleWindowInfo function, which is available on Windows95 and above, however this function only allows you to set the size and position of the window, so you could just move them off to the side somewhere. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|