tags:

views:

59

answers:

3

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 main()
{
    system("\"%TESTCASES_PATH%SIP\\Provisioning\\CrHomeDnOfficeCodeDestCodeBySoap\\CreateHomeDnOfficeCode.bat\"");
    //system("\"%TESTCASES_PATH%SIP\\tests.bat\"");
    getch();

    return 0;
}
+7  A: 

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);
Andomar
Andomar,I still see the same issue..
Prabhu. S
@Prabhu. S: Maybe you have to expand the environment variable yourself (answer edited)
Andomar
@Andomar, you are right. That did the trick!
Prabhu. S
+2  A: 

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.

Frank Bollack
+1  A: 

With one caveat to both solutions : test them with a string that contains NO space too.

It might fail on some windows shells.

Johan Buret