We help IT Professionals succeed at work.

Can CFEXECUTE wait for a response?

section25 asked
I am trying to test a mail server by sending an email via telnet. I know CF can send emails, but if it fails, the failure does not get sent back to my web page. I need a web page that will test sending an email and get the response back from the mail server so I can process the information that comes back.

So basically, I am trying to issue telnet commands through cfexecute to send a message to the mail server, but all of the commands get sent at once and I need them to wait until the mail server responds.

Is there any way I can delay the sending of each command?

For example, I need to the following to happen:

- send the command "telnet server.domain.com"
- wait for it to respond
- send the command "EHLO"
- wait for it to respond
- send the command "MAIL FROM:me@mydomain.com"
- wait for response

Watch Question

You can set a timeout attribute which afaik will force cfexecute to wait until it receives a response

  timeout = "30"

would wait for 30 seconds

from docs:
Length of time, in seconds, that ColdFusion waits for output from the spawned program.

    * 0: equivalent to nonblocking mode.
    * A very high value: equivalent to blocking mode.

I haven't used it in the way you are proposing so I'm not sure what impact it would have on overall server performance (ie: would it block all requests?). Might have a look at cfthread to spawn an independent thread to handle that request. (which I have even les experieince with)


The timeout period is only for the total time it takes to execute the operation. It does not interact with the commands.

Thanks anyway.
cfexecute is a one shot thing but it can wait for something -else- to runs multiple cmds and report back

I assumed you would do all that within the cfexecute via something like ant

Ant can -do- telnet and should be able to do exactly what you need. for example see http://stackoverflow.com/questions/2731107/ant-telnet-is-hanging-on-a-simple-task

there's also an undoc'ed feature called cfant which might be useful http://www.codfusion.com/blog/post.cfm/coldfusion-9-wishlist-cfant-and-cfsvn


Thanks for the info. CFant seems interesting and seems mainly for building files for remote installation. I need something a bit more geared to what I am trying to accomplish.
Please do a search for ant and read up a bit. Yes ant is used for installs but it is also incredibly versatile and can do what your are trying to accomplish...and you can trigger an ant task using cfexecute

CFant is simply a helper tool to run the ant scripts and you don't need to use it. You can run ant tasks without it.

You -cannot- accomplish what you want to do with cfexecute without using some type of scripting. I'm sure you could also script it using perl, python, java, .net or even vbsrcipt but Ant is easy to learn and works well.


OK, I'll look into it some more. Thanks.
You would be better calling telnet directly in Java by adding a telnet client Java library into Coldfusion. This would be easier than it sounds. Then you would have direct control over the telnet connection rather than trying to interact through cfexecute which really doesn't have any state.

If you do a search for Java telnet clients you will find a lot of them. Let me know if you would like me to look into this further and provide details of how to call these libraries through Coldfusion.

I believe this would solve your issue without too much trouble. I am happy to provide more info if it is helpful.
Ant did not pan out so I ended up using CFX_EXEC which did what I needed it to do.