同步操作将从 OpenHarmony/docs 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
This section describes how to add a shell command test using static registration and dynamic registration.
Development process:
Define the cmd_test function to be called to add a command.
Use the SHELLCMD_ENTRY function to add the new command.
Add a parameter to the liteos_tables_ldflags.mk link options for linking to the new command.
Recompile the code and run it.
Define the cmd_test function to be called to add a command.
#include "shell.h"
#include "shcmd.h"
int cmd_test(void)
{
printf("hello everybody!\n");
return 0;
}
Add the new command.
SHELLCMD_ENTRY(test_shellcmd, CMD_TYPE_EX, "test", 0, (CMD_CBK_FUNC)cmd_test);
Add a parameter to the link options for linking to the new command.
Add -utest_shellcmd to the LITEOS_TABLES_LDFLAGS option in the liteos_tables_ldflags.mk file.
Recompile the code.
make clean;make
Run the help command to view all the commands registered in the system.
The command output contains the test command (the following command output is for reference only.)
OHOS # help
*******************shell commands:*************************
arp cat cd chgrp chmod chown cp cpup
date dhclient dmesg dns format free help hwi
ifconfig ipdebug kill log ls lsfd memcheck mkdir
mount netstat oom partinfo partition ping ping6 pwd
reset rm rmdir sem statfs su swtmr sync
tftp touch umount uname test systeminfo task telnet
watch writeproc
Development process:
Use the osCmdReg function to add a new command.
Recompile the code and run it.
Call the osCmdReg function from the app_init function to dynamically register the command.
#include "shell.h"
#include "shcmd.h"
int cmd_test(void)
{
printf("hello everybody!\n");
return 0;
}
void app_init(void)
{
....
....
osCmdReg(CMD_TYPE_EX, "test", 0,(CMD_CBK_FUNC)cmd_test);
....
}
Recompile the code.
make clean;make
Run the help command to view all the commands registered in the system.
The command output contains the test command.
OHOS # help
*******************shell commands:*************************
arp cat cd chgrp chmod chown cp cpup
date dhclient dmesg dns format free help hwi
ifconfig ipdebug kill log ls lsfd memcheck mkdir
mount netstat oom partinfo partition ping ping6 pwd
reset rm rmdir sem statfs su swtmr sync
tftp touch umount uname test systeminfo task telnet
watch writeproc
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。