[英]C program for executing 'echo' on a target with no /bin directory
Let us say I cross-compile this code for ARM from a host Linux system: 我们假设我从主机Linux系统交叉编译ARM代码:
#include <stdio.h>
#include <unistd.h>
#include <dirent.h>
int main (void) {
return execl ("/bin/echo", "echo", NULL);
}
I got a binary echoFromC 我有一个二进制echoFromC
The problem is on my target where this binary would run, has no /bin, /usr etc. So it will not execute the command. 问题在于我的目标,这个二进制文件将运行,没有/ bin,/ usr等。所以它不会执行命令。
So I want that the final binary should contain every thing required to excute "echo". 所以我希望最后的二进制文件应该包含执行“echo”所需的所有内容。 It shouild not look for /bin/echo (since it is not there).
它不要寻找/ bin / echo(因为它不存在)。
How do I do this? 我该怎么做呢?
Actually I have to implement: 实际上我必须实现:
bash> echo 240 > /sys/class/gpio/export
bash> echo out > /sys/class/gpio/gpio240/direction
bash> echo 1 > /sys/class/gpio/gpio240/value
in ac program 在交流计划
You could implement those echo
functions in C, for example to implement echo 240 > /sys/class/gpio/export
, you could do something like 您可以在C中实现这些
echo
函数,例如实现echo 240 > /sys/class/gpio/export
,你可以做类似的事情
FILE *fh;
fh = open("/sys/class/gpio/export", "w+");
if (fh == NULL) { /* fopen failed */ }
fwrite("240\n", 1, 4, fh);
fclose(fh);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.