gpt4 book ai didi

powershell - 是否可以在cfexecute中获得Powershell输入的代码行对Coldfusion的响应?

转载 作者:行者123 更新时间:2023-12-02 23:41:32 33 4
gpt4 key购买 nike

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

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

谢谢

最佳答案

有两个问题:

  • 语法有点错误。除去参数字符串中的start。使powerShell.exe成为可执行文件也更加简单。
  • "timeout"可能导致命令在甚至没有收到输出之前就返回。将其增加到大于0的值,变量将被填充。

    ... [Default Timeout 0] starts a process and returns immediately. ColdFusion may return control to the calling page before any program output displays. To ensure that program output displays, set the value to 2 or higher.



    将超时增加到大于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#">

    关于powershell - 是否可以在cfexecute中获得Powershell输入的代码行对Coldfusion的响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41020705/

    33 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com