dousi6087 2016-09-06 14:24
浏览 718
已采纳

'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 15: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条)

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?