2

我正在尝试使用不同的属性(如 errorVariable、Variable、errorFile、outputFile)将 Powershell 的输出返回给 ColdFusion,但没有成功。

冷融合代码 -

<cfset hello = "hello">
<cfexecute name="C:\windows\system32\cmd.exe" 
arguments="/c start c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe C:\Users\raimonds\Desktop\lala.ps1 '#hello#'" 
variable="test">

<cfdump var="#test#">

而powershell代码 -

param([string]$hello)

Write-Host $hello

谢谢

4

1 回答 1

2

有两个问题:

  1. 语法有点不对劲。去掉start参数字符串中的 。使 powerShell.exe 成为可执行文件也更简单。

  2. 超时”可能会导致命令在接收到输出之前返回。将其增加到大于 0 的值,变量将被填充。

    ... [默认超时 0] 启动一个进程并立即返回。ColdFusion 可能会在显示任何程序输出之前将控制权返回给调用页面。要确保显示程序输出,请将值设置为 2 或更高。

    将超时时间增加到大于 0 的值,您应该会看到结果。

注意:始终捕获任何错误,以便代码可以相应地处理任何问题。

<cfset inputVar = "test value here">
<cfexecute name="c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe" 
    arguments="C:\path\to\yourScript.ps1 '#inputVar#'" 
    variable="result"
    errorvariable="err"
    timeout="2">

<cfdump var="#result#">
<cfdump var="#err#">
于 2016-12-07T15:57:57.127 回答