为 Capl 函数 sysExecCmd 设置相对路径
Set relative path for Capl function sysExecCmd
我有以下代码行。我想设置相对路径而不是硬编码路径,因为目前在下面的第二个参数中设置了-
sysExecCmd("Unlock_Ecu.bat","","D:\Program Files\ToolPath");
应替换为:
sysExecCmd("Unlock_Ecu.bat","","...\ToolPath");
如何在 Capl 的 sysExecCmd 函数中实现?
来自 sysExecCmd
文档(强调我的):
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
.
示例:
char absPath[256];
GetUserFilePath("Unlock_Ecu.bat", absPath, 256);
SysExecCmd(absPath, "");
我通常会按照下面的方式进行:
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");
}
我有以下代码行。我想设置相对路径而不是硬编码路径,因为目前在下面的第二个参数中设置了-
sysExecCmd("Unlock_Ecu.bat","","D:\Program Files\ToolPath");
应替换为:
sysExecCmd("Unlock_Ecu.bat","","...\ToolPath");
如何在 Capl 的 sysExecCmd 函数中实现?
来自 sysExecCmd
文档(强调我的):
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
.
示例:
char absPath[256];
GetUserFilePath("Unlock_Ecu.bat", absPath, 256);
SysExecCmd(absPath, "");
我通常会按照下面的方式进行:
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");
}