C语言程序如何读取cmd命令的返回值?
3个回答
展开全部
fp=popen(cmd,"r")
fgets(buffer, sizeof(buffer), fp);
strncmp(buffer, "success", strlen("success"))
---------------------------------------------------
pid = vfork();
if (pid == 0)
execl("/bin/sh", "sh", "-c", cmd, (char*)0)
else
while(waitpid(pid, &status, 0) < 0)
......
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询