In the following statement :
system("%TESTCASES_PATH%SIP\\test.bat");
the %TESTCASES_PATH% gets resolved to "C:\Program Files..." .
As such the result of calling the system is :
"'C:\Program' is not recognized as an internal or external command.."
'C:\Program' is thought as a executable..
How to overcome the above issue?
EDIT: Trying out what is proposed in the answers, I get to see the same behavior. The following is the actual code:
#include <stdio.h>
#include<conio.h>
int ma开发者_运维百科in()
{
system("\"%TESTCASES_PATH%SIP\\Provisioning\\CrHomeDnOfficeCodeDestCodeBySoap\\CreateHomeDnOfficeCode.bat\"");
//system("\"%TESTCASES_PATH%SIP\\tests.bat\"");
getch();
return 0;
}
Use double quotes to pass the entire path as the executable / batch file:
system("\"%TESTCASES_PATH%SIP\\test.bat\"");
Otherwise, what's after a space becomes the first command-line parameter.
EDIT: Perhaps on your setup, %TESTCASES_PATH%
is not expanded by the system()
function. On most systems, you can retrieve the value of an environment variable with getenv()
:
char cmd[FILENAME_MAX];
snprintf(cmd, FILENAME_MAX, "\"%s\\test.bat\"",
getenv("TESTCASES_PATH"));
system(cmd);
What about:
system("\"%TESTCASES_PATH%SIP\\test.bat\"");
The additional double quotes in the string allow to pass file names with white space to the system call.
With one caveat to both solutions : test them with a string that contains NO space too.
It might fail on some windows shells.
精彩评论