我想用C写一个脚本,只在Ubuntu系统上运行。我得到了操作系统的名称。但。我没有定义if子句。谢谢你的帮助
像这样的算法:
发布于 2018-07-23 22:14:28
我认为检查操作系统名称最可靠的方法是使用uname
实用程序。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int match_OS(const char* name) {
FILE *p;
int result;
char *s = malloc(1024);
p = popen("uname -v", "r");
s = fgets(s, 1024, p);
result = (strstr(s, name) != NULL);
pclose(p);
free(s);
return result;
}
int main() {
if (match_OS("Ubuntu")) {
puts("This is Ubuntu");
}
else {
puts("This isn't Ubuntu");
}
return 0;
}
https://stackoverflow.com/questions/51479705
复制相似问题