2

Here is a sample:

<cfset cmd="get-date -format g" /> 
<cfset args="-inputformat none -Command " & cmd />
<cfoutput>
    <cfexecute name="powershell.exe" variable="result" errorvariable="err"
               arguments="#args#" timeout="99" />
    <p>Result: <cfif result neq "">#result#<cfelse>None</cfif></p>
    <p>Error: <cfif err neq "">#err#<cfelse>None</cfif></p>
</cfoutput>

On Windows 2008 R2 with ColdFusion 10, this will accurately put the PowerShell command's output into the result variable. After upgrading to ColdFusion 11, this code will execute with no errors but there is no result.

If I try some other command that will save a file or something, there is no evidence that the PowerShell command is even being executed.

I've tested against an upgraded ColdFusion 11, and by installing ColdFusion 11 fresh. In all cases, I'm using CF as a stand-alone server. I've tried with or without CF 11 updates/hotfixes. I've verified that the user account that CF is running as has permission to execute PowerShell.

Your help and/or corroboration of this problem is appreciated. What am I missing? If this is a bug, any ideas on how to execute some PowerShell commands from CF 11 moving forward?

Thanks for taking a look!

James A Mohler
  • 11,060
  • 15
  • 46
  • 72
  • 3
    First, try specifying the full path to powershell.exe. – Leigh Jun 09 '15 at 23:36
  • As @Leigh suggested you may specify full path to powershell.exe or you can add it's path to environment variables `path` and call as it is. – Pankaj Jun 10 '15 at 06:03
  • @Leigh Thanks for your recommendation. This does not help. Anyone with CF 11 on Windows, can you try this code and see if you actually get the results to output? It would be nice to confirm if this is a global problem or indeed a configuration problem on my setups. – Josh Curtiss Jun 11 '15 at 13:22
  • Maybe you did this already, but ... have you tested it from the command prompt, using hard coded strings? Specifically A) Login under the CF service account. Open a command prompt. Run the command `c:\path\to\powershell.exe -inputformat none -Command get-date -format g"`. B) If it works, run the *exact* same command with cfexecute (no variables) ie ``. C) If you still get the same result, try putting the command in a .bat file, and calling the .bat file instead. – Leigh Jun 11 '15 at 18:45
  • @Leigh I have tried it from the command line and things work. That's part of my point that it seems to be a problem with CFEXECUTE. I have tried hardcoding all the arguments as suggested too. I'll try executing a batch script like your suggestion C recommends. – Josh Curtiss Jun 17 '15 at 14:00
  • @Leigh and everyone, I put it in a batch script, which I can execute on command line and it works. When I simply execute the batch script from CFEXECUTE, I get no results. I can do a batch command, like ECHO, and that will output when the batch script is executed from CFEXECUTE. But the PowerShell command does not execute within CFEXECUTE. I'm stumped, hence my posting this here on Stack Overflow. Please, any ideas anyone? Has anyone duplicated this on their CF 11 environment? – Josh Curtiss Jun 17 '15 at 14:50
  • You are not getting any timeouts or seeing extra processes left running in the Task Manager, correct? *tried it from the command line and things work.. That's part of my point* Yep, I understood that, but the point of the tests above was to make absolutely certain the problem was not due to permissions OR some subtle syntax difference :) *If* you tried [all of the steps above - exactly](http://stackoverflow.com/questions/30743625/cfexecute-seems-to-not-execute-powershell-in-coldfusion-11#comment49627471_30743625), and it still does not work, then unfortunately I am out of ideas. – Leigh Jun 23 '15 at 13:22
  • I didn't execute your step B exactly, because calling cmd.exe you need to put /C before the command you want to execute in order to cleanly exit after executing the command, otherwise it will timeout. But other than that caveat, I tried all your steps exactly. Thanks for your help. – Josh Curtiss Jun 23 '15 at 21:48
  • @JoshCurtiss - Just noticed your response now. S.O. only notifies commenters under certain conditions, like using "@userName - (message)" format. Anyway, yes it is acceptable to add "/C". In fact it used to be required for some programs back in CF8 as part of a work around for a [bug involving cfexecute and StdErr output](http://stackoverflow.com/questions/1002025/how-do-i-keep-cfexecute-from-hanging-after-a-printstacktrace/1002585#1002585). That is actually why I asked if there were any extra processes in the Task Manager. It is probably not the issue, but certainly does not hurt to check. – Leigh Jun 27 '15 at 15:16

1 Answers1

4

To folks facing this, see if the answer lies in updating the jvm that CF uses. By default, cf11 came (at least initially) with Java 1.8.0_25, which as I write in 2016 is dated.

Try updating to a later jvm version. Pete Freitag has a nice video on doing it, and I point to it in a blog post dealing with challenges if you find CF won't start after trying this:

http://www.carehart.org/blog/client/index.cfm/2014/12/11/help_I_updated_CFs_JVM_and_it_wont_start

And let us know here if updating the jvm helps.

charlie arehart
  • 6,590
  • 3
  • 27
  • 25