Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Function 如何在c文件中使用long命令运行系统功能?_Function_Command_Output Redirect_C Libraries - Fatal编程技术网

Function 如何在c文件中使用long命令运行系统功能?

Function 如何在c文件中使用long命令运行系统功能?,function,command,output-redirect,c-libraries,Function,Command,Output Redirect,C Libraries,运行此“.c”文件的可执行文件时,我无法在文本文件中获取命令的输出: char image_upload_cmd[100] = {'\0'}; sprintf(image_upload_cmd, "mcumgr conn show > /home/sample/statfile.txt"); system(image_upload_cmd); --> mcumgr command exists in '/usr/bin/'. --> conn, show are optio

运行此“.c”文件的可执行文件时,我无法在文本文件中获取命令的输出:

char image_upload_cmd[100] = {'\0'};

sprintf(image_upload_cmd, "mcumgr conn show > /home/sample/statfile.txt");
system(image_upload_cmd);

--> mcumgr command exists in '/usr/bin/'.
--> conn, show are options to that command.

我们可以使用系统函数来运行我在上面的问题中提到的命令

唯一的问题是,我运行此应用程序代码的板需要sudo权限才能创建该文件

只需添加“sudo”权限,如下所示: sprintf(图片上传命令,“sudo mcumgr conn show>/home/sample/statfile.txt”)

这将把输出重定向到statfile.txt