2

I have following line of code. I want to set relative path instead of hardcoded path as is presently set in 2nd argument below-

sysExecCmd("Unlock_Ecu.bat","","D:\\Program Files\\ToolPath");

Should be replaced as:

sysExecCmd("Unlock_Ecu.bat","","...\\ToolPath");

How can I do it in sysExecCmd function of Capl ?

sergej
  • 17,147
  • 6
  • 52
  • 89
Tkumari
  • 23
  • 1
  • 4

2 Answers2

2

I usually do it as listed below:

variables
{
  char absPath[256];   // Holds Abs Path for current CFG file
  // Relative Path for ToolPath folder
  char ToolPath[100]= "\\ToolPath\\";
}

on preStart
{
  /* Get Abs path of current config file */
  GetUserFilePath("", absPath, 256);
  Exec_Batch();
}

void Exec_Batch()
{
  /* Get Absolute Path for executing Bat file */
  char absToolPath[256];
  strncat(absToolPath, absPath, strlen(absPath));
  strncat(absToolPath, ToolPath, strlen(absToolPath) + strlen(ToolPath)); 

  write("Executing Batch File");

  sysExecCmd("Unlock_Ecu.bat","",absToolPath);

  write("Finished execution of Batch File");
}
sergej
  • 17,147
  • 6
  • 52
  • 89
1

From the sysExecCmd documentation (emphasis mine):

To avoid absolute paths in CAPL code and to be independent of the execution platform, proceed as follows:

Add the application to be started to the User Files in CANoe Options dialog. At application call the absolute path can be resolved with the CAPL function GetUserFilePath.

Example:

char absPath[256];
GetUserFilePath("Unlock_Ecu.bat", absPath, 256);
SysExecCmd(absPath, "");
sergej
  • 17,147
  • 6
  • 52
  • 89