I want to call another binary executable file when I start my app. This bin file will generate a .txt file with content "hello, world!".
Below is my code.
void checkFilePermissions(const char* filePath) {
if (access(filePath, X_OK) != -1) {
ALOGI( "File has execute permission: %s" , filePath);
} else {
ALOGI( "File does not have execute permission: %s" , filePath);
}
}
int executeBinary(const char *filePath) {
char *args[] = {strdup(filePath), nullptr};
if (execvp(args[0], args) == -1) {
ALOGI( "execvp failed: %s" , strerror(errno));
return -1;
}
return 0;
}
void OnStart() override {
const char *filePath = "/data/data/com.magicleap.capi.sample.eye_tracking/files/bin/hello";
checkFilePermissions(filePath);
int result = executeBinary(filePath);
if (result == -1) {
ALOGI("Failed to execute binary.");
} else {
ALOGI("Binary executed successfully with exit code: %d", result);
}
... // other code
}
Below is the Log:
*File has execute permission: /data/data/com.magicleap.capi.sample.eye_tracking/files/bin/hello*
*execvp failed: Permission denied*
*Failed to execute binary.*
How can I realize my idea?