我想执行以下命令
ubus -S call network.interface status '{"interface": "lan"}'
与C中的execvp
:
char* arg[] = {"ubus", "-S", "call", "network.interface" , "status", "'{\"interface\": \"lan\"}'", NULL};
execvp(arg[0],arg);
但命令不起作用。我做了一个调查,我发现原因是第五个参数('{"interface": "lan"}'
)包含一个特殊的charachter '
,看起来被execvp
忽略了。
如何避免这个问题?
错误的路径..论点读取{"interface": "lan"}
,而不是'{"interface": "lan"}'
。引号仅适用于shell,因此它知道内部的空格属于参数,而不是两个参数之间的分隔符。 ubus
永远不会看到他们。
编辑:更好的说ubus
永远不应该看到它们,因为在你的实现中,它确实存在,而这只是ubus
的错误语法。
您没有显示您的代码,但是等效的execvp
调用看起来像这样:
char *args[] = {
"ubus", "-S", "call", "network.interface", "status", "{\"interface\": \"lan\"}", NULL
};
execvp("ubus", args);