I'm trying to get Powershell's output back to ColdFusion with different attributes like errorVariable, Variable, errorFile, outputFile but with no success.
Coldfusion code -
<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#">
And the powershell code -
param([string]$hello)
Write-Host $hello
Thank you
There are two issues:
The syntax is a bit off. Get rid of the start
in the argument string. It is also simpler to make powerShell.exe the executable.
The "timeout" is likely causing the command to return before the output is even received. Increase it to something greater than 0 and the variable will be populated.
... [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.
Increase the timeout to something greater than 0 and you should see the result.
NB: Always capture any errors so the code can handle any issues accordingly.
<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#">