douzha8489 2014-05-24 02:30
浏览 45
已采纳

如何在Linux中使用C编程检查我的php和pear版本?

If possible, I don't want to use string detection method where you use string functions to detect the version in a given string output. If it isn't possible then please disregard what I just typed.

Is there a function to do it like uname() or do I have to write my own function? If so, please give me a headstart or you can make my life easier by teaching me how to do it. Thanks!

Btw, I'm using dreamhost shared server if that might help and yes, it has gcc, php5.3 and pear 1.9.4 installed.

  • 写回答

1条回答 默认 最新

  • doz59484 2014-05-24 06:20
    关注

    Sorry to disappoint, but that is what you will need to do. The popen function is your friend. Simply call "pear -V" in read mode with popen and store the information in a buffer that you can easily parse to isolate the version numbers for both pear and PHP. It can be done much cleaner, but the gist of it is:

    FILE *pfd;
    char buffer[1024];
    char *bp = buffer;
    char tmp[100];
    size_t len;
    size_t line = 0;
    
    if ((pfd = popen ("pear -V", "r")) == NULL) {
        fprintf (stderr, "error: failed to open pipe.");
        return 1;
    }
    
    while (fgets (tmp, 1023, pfd) != NULL && line < 2)
    {
        len = strlen (tmp);
        strncpy (bp, tmp, len);
        bp += len;
        line++;
    }
    
    pclose (pfd);
    
    printf ("
    buffer:
    
    %s
    
    ", buffer);
    

    Output:

    buffer:
    
    PEAR Version: 1.9.4
    PHP Version: 5.3.8
    

    The parsing of the version numbers is left for you.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 人在外地出差,速帮一点点
  • ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改
  • ¥15 Windows 系统cmd后提示“加载用户设置时遇到错误”
  • ¥50 vue router 动态路由问题
  • ¥15 关于#.net#的问题:End Function
  • ¥15 无法import pycausal
  • ¥15 VS2022创建MVC framework提示:预安装的程序包具有对缺少的注册表值的引用
  • ¥15 weditor无法连接模拟器Local server not started, start with?
  • ¥20 6-3 String类定义
  • ¥15 嵌入式--定时器使用