1

All I get in my browser is a blank screen. If I don't use IsDefined, I would get an error in the page stating the variable doesn't exists.

If I misspell a command (example: using /bin/bsh instead of /bin/bash), I get an exception stating CF cannot find the program. So it seems to be working. I just want to check if it's really running.

Here's my code:

------
<cfexecute name="/bin/ls" arguments=" -la /" errorVariable="error" variable="result"></cfexecute>
<cfif IsDefined("result")>
    <cfdump var="#result#">
</cfif>
<cfif IsDefined("error")>
    <cfdump var="#error#">
</cfif>

<cfexecute name="/bin/bash" arguments=" -c '/bin/ls -la /'" errorVariable="error" variable="result"></cfexecute>
<cfif IsDefined("result")>
    <cfdump var="#result#">
</cfif>
<cfif IsDefined("error")>
    <cfdump var="#error#">
</cfif>
James A Mohler
  • 11,060
  • 15
  • 46
  • 72
mrjayviper
  • 2,258
  • 11
  • 46
  • 82

2 Answers2

3

You need to specify a timeout on cfexecute in order to get a valid result/error sequentially.

The default timeout is 0, which is non-blocking, which means your command is executing asynchronously. This means you don't immediately have a result.

I'm not sure whether, to Adobe, "non-blocking" means the variable and error attributes are ignored completely or eventually set. If you're curious you could toss in a cfsleep and find out, just please not in production. :)

Rain
  • 321
  • 1
  • 8
  • Always forget about the [timeout](https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-tags/tags-d-e/cfexecute.html) *"... To ensure that program output displays, set the value to 2 or higher."*. Would make more sense if that was the default. – SOS Aug 09 '18 at 18:39
  • It's weird in general. [Lucee](http://docs.lucee.org/reference/tags/execute.html) has a `terminateontimeout` attribute but presumably ACF will allow the process to run asynchronously after the timeout, and that's why they _recommend_ 2+ seconds if you want output immediately. Or does it terminate the process and you **never** get that output? In one of those cases, you still might need a spinlock or `structkeyexists`. – Rain Aug 09 '18 at 20:12
  • Not sure about 2016 and higher, but in earlier versions Adobe doesn't terminate the process. It just keeps running. So if it exceeds the timeout, you never get the output, just a timeout error. If the program doesn't exit automatically, like cmd.exe, it'll remain running indefinitely. – SOS Aug 10 '18 at 16:01
0

You have to specify the Absolute path of the application to execute.On Windows, specify an extension, for example, C:\myapp.exe.

I've run the my sqlCMD by using cfexecute, Here I've passed the absolute path of an MS sql server.

<cfexecute name="C:\Program Files\Microsoft SQL Server2016\Client SDK\ODBC\130\Tools\Binn\SQLCMD.EXE" arguments=" -S localhost -U sa -P sqlPwd@12## -i" timeout="0" errorFile="#logsDir#/#TableSqls.name#_error.txt">

</cfexecute>

I hope it's will help you.

Kannan.P
  • 1,263
  • 7
  • 14