要运行的终端命令是:
cd folder1/folder2
sudo ./runnable
我正在考虑一种解决方案,例如:
exceute.run("cd folder1/folder2","sudo ./runnable")
在我的C ++代码中。此外,这应该以SUPERUSER的身份完成。请帮忙 !!
为什么不只使用显式路径调用程序?
例如,如果您的程序位于/ 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运行程序的更多信息,请参见此链接。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句