Store output of system(file) command as a string in C

后端 未结 3 1257
你的背包
你的背包 2021-01-19 05:02

To get the type of file we can execute the command

system(\"file --mime-type -b filename\");

The output displays in to terminal.But could

3条回答
  •  悲&欢浪女
    2021-01-19 05:22

    See the man page of system: It does not return the output of the command executed (but an errorcode or the return value of the command).

    What you want is popen. It return a FILE* which you can use to read the output of the command (see popen man page for details).

提交回复
热议问题