coldfusion 8 and 2016: CFEXECUTE not returning result/error

998 views Asked by At

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>
2

There are 2 answers

1
Kannan.P On

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.

3
Rain On

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. :)