如何从存储在其他文件夹中的C ++运行linux可执行文件

时间:2015-12-05 04:42:05

标签: c++ linux automation

要运行的终端命令是:

cd folder1/folder2
sudo ./runnable

我正在考虑一个解决方案,例如:

exceute.run("cd folder1/folder2","sudo ./runnable")

在我的C ++代码中。此外,这应该作为SUPERUSER完成。请帮忙!!

1 个答案:

答案 0 :(得分:0)

为什么不使用显式路径调用您的程序?

例如,如果您的程序位于/ projects / folder1 / folder2中, 那么你会有:

#include <cstdlib>
#include <iostream>

int main()
{
   std::cout<<"Starting runnable executable..."<<std::endl;
   std::system("cd /home/youbot/applications; sudo ./runnable"); 
   return 0;
}


chmod 775 /projects/folder1/folder2/runnable

不建议以root身份运行程序。

有关为何不建议使用sudo运行程序的详细信息,请参阅this链接。