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 用lstm来预测股票价格
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上