You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过CFEXECUTE获取.bat文件返回的CPU使用率值?

Fixing CFEXECUTE Variable Undefined Error in ColdFusion 2021

The core issue with your code is the missing timeout attribute in the <cfexecute> tag. When using the variable attribute to capture output directly, ColdFusion requires a timeout value to wait for the external batch script process to complete before populating the variable. Without this setting, CFEXECUTE may not wait for the script to finish, leaving the Usage variable undefined.

Corrected CFEXECUTE Code

Add the timeout attribute (set to a reasonable value like 5 seconds) to your tag:

<cfexecute name="#PathToBatchFile#" variable="Usage" timeout="5">
<cfdump var="#Usage#">

Why This Works

  • The timeout parameter forces ColdFusion to pause execution until the batch script finishes (or the timeout expires), ensuring the script's output is captured into the Usage variable.
  • Since your batch script already outputs the CPU usage as a plain numeric value, this variable will hold that result once the process completes.

Additional Validation Steps

  • Verify PathToBatchFile is a fully resolved path (use expandPath() to confirm, e.g., expandPath("./cpu_usage.bat")).
  • Confirm the ColdFusion service user has permission to execute the batch file (your working outputfile approach already implies permissions are valid).

内容的提问来源于stack exchange,提问作者Huckleberry

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 16:10:56