dousi6087 2016-09-06 06:24 采纳率: 100%
浏览 736
已采纳

'C:\ wmic'不被识别为内部或外部命令,可操作程序或批处理文件

I want to display in a browser the load percentage of a cpu trough php. This is the code I am using:

$command ="C:\\wmic cpu get loadpercentage"; 
echo shell_exec("$command 2>&1 ; echo $?" );

This is the output:

'C:\wmic' is not recognized as an internal or external command, operable program or batch file.

What am I missing?

Update - 1

Change the code to allow spaces between words: $command ="C:\\wmic^ cpu^ get^ loadpercentage";

'C:\wmic cpu get loadpercentage' is not recognized as an internal or external command, operable program or batch file.

Now the entire line of code is being read, not only 'C:\wmic'

  • 写回答

3条回答 默认 最新

  • dongliping003116 2016-09-06 07:46
    关注

    You have two problems, both of which we explored in the comments above:

    1. The actual WMIC binary is located at C:\Windows\System32\wbem\WMIC.exe, not C:\wmic. That path needs to be used in your PHP command.

    2. You are trying to use Unix-style shell concepts (redirecting STDERR to STDOUT, chaining commands with ;, and using echo and $?) on a Windows system.

      Simply running the command without all that stuff should work:

      echo shell_exec("C:\\Windows\\System32\\wbem\\WMIC.exe cpu get loadpercentage");
      
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部