View comments | RSS feed
Contents > CFML Reference > ColdFusion Tags > cfexecute PreviousNext

cfexecute

Executes a ColdFusion developer-specified process on a server computer.

Extensibility tags, Flow-control tags

<cfexecute 
name = " ApplicationName "
arguments = "CommandLine Arguments"
outputFile = "Output file name" variable = "variable name"
timeout = "Timeout interval">
...
</cfexecute>

cfcollection, cfindex, cfobject, cfreport, cfsearch, cfwddx

ColdFusion MX 6.1:

Attribute

Req/Opt

Default

Description

name

Required

 

Absolute path of the application to execute.

On Windows, you must specify an extension; for example, C:\myapp.exe.

arguments

Optional

 

Command-line variables passed to application. If specified as string, it is processed as follows:

  • Windows: passed to process control subsystem for parsing.
  • UNIX: tokenized into an array of arguments. The default token separator is a space; you can delimit arguments that have embedded spaces with double quotation marks.

If passed as array, it is processed as follows:

  • Windows: elements are concatenated into a string of tokens, separated by spaces. Passed to process control subsystem for parsing.
  • UNIX: elements are copied into an array of exec() arguments.

outputFile

Optional

 

File to which to direct program output. If no outputfile or variable attribute is specified, output is displayed on the page from which it was called.

If not an absolute path (starting a with a drive letter and a colon, or a forward or backward slash), it is relative to the ColdFusion temporary directory, which is returned by the GetTempDirectory function.

variable

Optional

 

Variable in which to put program output. If no outputfile or variable attribute is specified, output is displayed on page from which it was called.

timeout

Optional

0

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

  • 0: equivalent to non-blocking mode.
  • A very high value: equivalent to blocking mode

If the value is 0:

  • ColdFusion 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.
  • If the outputFile attribute is not specified, any program output is discarded

Do not put other ColdFusion tags or functions between the start and end tags of cfexecute. You cannot nest cfexecute tags.

Throws the following exceptions:

The time out values must be between zero and the longest time out value supported by the operating system.

<h3>cfexecute</h3>
<p>This example executes the Windows NT version of the netstat network 
monitoring program, and places its output in a file. <cfexecute name = "C:\WinNT\System32\netstat.exe" arguments = "-e" outputFile = "C:\Temp\output.txt" timeout = "1"> </cfexecute>

Contents > CFML Reference > ColdFusion Tags > cfexecute PreviousNext

ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting

Version 6.1

Comments are no longer accepted for ColdFusion MX 6.1. ColdFusion 8 is the current version.

Comments


oystein.halvorsen said on Nov 4, 2003 at 5:57 AM :
Quoting the cfexec documentation:

* UNIX: tokenized into an array of arguments. The default token separator is a space; you can delimit arguments that have embedded spaces with double quotation marks.

We have tried this, but it doesn't work appropriately. The double quotes are sent as single quotes prefixing the first and suffixing the last "word" respectively, and each "word" is sent as a separate parameter instead of one parameter containing the whole space-embedded string.
fraxen said on Nov 5, 2003 at 12:14 AM :
We have gotten a confirmation that this is a bug in CFMX6.1 on Linux/Unix (bugid 50604). At this time I was unable to locate a tech-note on this issue. The confirmation was give by Hiroshi Okugawa of Macromedia to an inquiry to the CF-Talk list.
francesco.strazzulla said on Nov 19, 2003 at 8:02 AM :
We have a problem with the tag CFEXECUTE and a 16bit application..
We have tried this code that is working in ColdFusion 6.0 but after an'upgrade to ColdFusion 6.1 the code now is not working..

<CFEXECUTE
NAME="#application.avpc5serverpath#\dll\PKZIP.EXE"
ARGUMENTS="-d #application.avpc5serverpath#\tmp\#random_dir#\#file_name# avpc4/data/avpc4/*.* avpc4/data/archivio/*.*"
TIMEOUT="10"
OUTPUTFILE="#application.avpc5serverpath#\tmp\#random_dir#og\output1.txt"
>
</cfexecute>

the problem is related with the pkzip.exe application...
when we run this code in the server side(windows 2000 professional) we receive an error windows with the message "c:\winnt\system32\ntvdm.exe error setting the enviroment for the application....."

thanks for your help
no screen name said on mar 8, 2004 at 12:11 pm :
desperate!!!!
i am trying (6 hours) to get cfexecute to run an instance of notepad.exe.

when the script runs, no error is given, everything seems ok, but it does not run notepad!!!!

help!
georgia_geno said on mar 15, 2004 at 6:53 am :
i am trying to get network inf via nbtstat a #ipaddress#
i think this will work but i am having issues with the argument syntax.

do you have examples of syntax with the ipaddress given. if i figure this out i will post it for other users.

thanks,geno
jasonuo said on jun 7, 2004 at 11:46 am :
after upgrading to mx 6.1, i had some difficulty with the cfexecute tag. i tried several different methods of executing an app, and the page would always timeout, and the executable would still be on the server's process list. the solution i found was to go to the server and run "dcomcnfg". go to the "default security" tab, click on "edit default" under "access permissions", and add the account which the iis service uses to execute anonymously (this is generally iusr_machinename).
carehart said on jul 14, 2004 at 1:34 pm :
useful tip above. jasonuo.

here's another: i was having heartache trying to run a command and view its output, whether writing to the screen or using the new cfmx attribute variable. after much gnashing of teeth, i finally reverted to the older outputfile attribute and sure enough, the output was being written to the file. why would it work going to a file but not to a variable or the screen?

turns out you have to read the docs really carefully: if you don't specify a timeout (or set it to 0), the execution is asynchronous. a new thread is spawned to do the work, and there is no output written to the variable (or screen, if no variable or outputfile is offered). it's written only to the outputfile (or discarded if there is none).
no screen name said on aug 13, 2004 at 1:38 pm :
in windows 2003, you cannot use cfexecute... did anybody get this to work?
patboens said on aug 20, 2004 at 5:29 am :
i think your notepad application has been launched several times but keeps hidden as it is probably executed with no console/display.

take a look in the task manager if you see it.

pat
no screen name said on oct 9, 2004 at 11:24 am :
i'm trying to start a batch file that will create a file independent of cf. the batch file works great but i can't get the cfexecute function to run it. there is no display out, just a file. any ideas?
fhaer said on oct 12, 2004 at 10:48 am :
be sure you understand the timeout parameter when you use this function!! the default value of zero executes the program in the background without returning any results to cold fusion

if you need to see the results you must specify a value for timeout
crjangel said on oct 29, 2004 at 6:55 am :
i do have cfexecute working in os windows 2003 web server
arden o said on nov 2, 2004 at 8:26 pm :
i too am having problems with using cfexecute -- to run a visual foxpro executable - the exe file remains in the services list after the cfexecute time expires -- since cf is running on xp home, i am using the cf internal internet sever instead of iis -- tried run tdcomcnfg and changing the vfp access permissions to no avail (based on jasonuo suggestions -- an empty output file is generated and control is returned to cf, rerunning the code just creates another vfp exe item in the services list. addes suggestions welcome
tibs75 said on nov 7, 2004 at 4:58 pm :
i've tried to run cfexecute on a solaris box to get the listing of a directory tree. cfexecute returns an empty space.

email me to tell me what i'm doing wrong.

here is the code:

<cfoutput>

<cfsavecontent variable="myvar">
<cfexecute name="/bin/ls"></cfexecute>
</cfsavecontent>

#myvar#

</cfoutput>

this was to overcome the problem with cfdirectory/cfftp in traversing a directory tree and get the mode flag... both of which again return an empty string. i require the permissions attributes for files and directories


thanks
dplusplus said on nov 12, 2004 at 11:13 am :
i followed jasonu0 instructions and that worked for me. although i also needed to change the cold fusion services to run using a specific user instead of the localsystem account.

very strange issue at first because i would get no errors when i run cfexecute command it would process that page fine but no action, and couldn't find anything in log files.
annoyed customer said on dec 19, 2004 at 8:28 pm :
<cfexecute name="#abspath('bin/shell')#" arguments="#cmd#" timeout=100></cfexecute>

<cfsavecontent variable="result">
<cfexecute name="#abspath('bin/shell')#" arguments="#cmd#" timeout=100>
</cfexecute>
</cfsavecontent>

in mx 6.1:
1.) the first version always returns returns an empty string instead of stdout. the second version works but is somewhat long-winded.
2.) abspath is a custom workaround for expandpath not handling absolute paths correctly (contrary to these docs)
3.) bin/shell is a custom workaround for no stderr support and other limitations/bugs.
4.) the documentation on this site is incomplete and frequently inaccurate
5.) docs do not explain why </cfexecute> is required or why <cfexecute ... /> doesn't work.
6.) no cfscript equivalent.
7.) no subprocess interaction (expect, wait, kill, etc...) or even basic write/read/evaluate/write on pipes.
8.) no process status (errorlevel) returned.
9.) syntax is ugly and excessive, why not <cfset result = cfexec('/bin/script arg1 arg2', opts...) ? />

in summary it has taken me nearly 12 hours to perform a basic operating system task. i'm mad as hell! this would have been a trivial task in any other language (except perhaps ms ones). scripting in director, flash and authorware was excellent but coldfusion is the worst language i've ever used - period.
annoyed customer said on dec 19, 2004 at 9:18 pm :
well, another hour (maybe two) wasted but i finally found the problem. the permissions on bin/shell were set incorrectly meaning the server did not have read permission. since cf throws an exception when bin/shell does not exist it should also throw one when it cannot be read or executed - but it does not. it returns an empty string and continues. grrrrrr..........
davidlam808 said on dec 23, 2004 at 2:23 am :
i created an exe in vb, when i run it in windows it works fine.

but when i run in using the cfexecute command, i see the process start but it doesn't run.

thanks
davidlam808 said on dec 23, 2004 at 11:11 am :
this is in reference to dplusplus and arden o.

i am having the same problem. when i execute it through cf, the process is under system.

dplusplus do i need to change it to admin username. can you provide instruction on how to change the user name.

thanks
hall said on dec 24, 2004 at 8:45 am :
if you are running coldfusion mx as a windows service on windows xp, go to control panel > administrative tools > services. right click the coldfusion mx application server entry and select properties, then select the log on tab. you can use this tab to change the account under which coldfusion mx runs.
spage said on jan 20, 2005 at 2:04 pm :
if you set a non-zero timeout, you can get another exception not listed in the docs:
cfcatch.message="timeout period expired without completion of <name>"

i found this on solaris with
<cfexecute name="/usr/bin/sleep" arguments="50" outputfile="/tmp/junk.sleepr" timeout="5">
i.e. sleep for 50 seconds but a 5 second timeout.

cheers!
brentil said on mar 1, 2005 at 12:58 pm :
as francesco.strazzulla mentioned above i get the same error he reports when running cfmx 6.1 on a windows 2003 server.

"c:\winnt\system32\ntvdm.exe error setting the enviroment for the application....."

however i believe this only occurs when running 16-bit applications such as an older zip program or the norton command line anti virus. it throws that error to the screen with the option to ignore or cancel. if you ignore in time it'll allow it to run. i've found many people online with thsi exact same issue but with other applications.

it appears that what is happening is the execute is possibly attempting to run the commands using command.com instead of cmd. this is possibly due to it interpreting 2003 as actually being win9x kernel instead of nt.
no screen name said on mar 2, 2005 at 4:35 am :
cfexecute is giving error
an exception occurred when invoking an external process.
the cause of this exception was that: java.io.ioexception: createprocess: foldername.asp error=2.
command used - <cfexecute name = "test.sh" outputfile="output.txt">

</cfexecute>

can anybody tell what is the cause of this error?
jrunrandy said on mar 7, 2005 at 2:42 pm :
if the solutions posted on this page do not fix your problem, i suggest posting your issue to the online forums: http://webforums.macromedia.com/coldfusion.
hankm said on mar 10, 2005 at 6:53 am :
i ran into an interesting anomaly that i thought i should document here in case it bites someone else.

i have a cf mx 6.1 template that uses cfexecute to run a foxpro program. it was working on one of my cf servers but not on the other, and as far as i know they're configured pretty much identically. it was driving me nuts.

the tag had a lot of arguments, and i had split the argument string up onto two lines for greater readability, and that turned out to be the problem -- when i restored all of the arguments onto one line, the problem disappeared.

i still have no idea why the "split" argument line worked on one of our cf servers but not on the other, but i thought i'd pass along the tip that splitting the argument string *may* cause problems.
pgarner said on mar 16, 2005 at 4:25 pm :
i was having the same problems as people above (executable hanging in the processes). i followed jasonuo's suggestion and the suggestion to change the cf service to run under an administrator account as opposed to the system account. all is now well. my executable to alter active directory actually runs using <cfexecute>. whew!
emunoz said on mar 22, 2005 at 10:29 am :
ben forta shared some code in this url:
http://www.cflib.org/udf.cfm?id=777

does anyone know how to grab the username or nwusername variables? you can see them when you execute the dos command of "set " if you're in a ntdomain/novell environment.
jrunrandy said on mar 30, 2005 at 1:08 pm :
emunoz:
you will get a better and quicker answer by posting questions like this to the online forums: http://webforums.macromedia.com/coldfusion
no screen name said on apr 4, 2005 at 8:41 pm :
i got this one also: "an exception occurred when invoking an external process. the cause of this exception was that: java.io.ioexception: createprocess: whateveryourappnameis.exe error=2"

solution: it came out that error=2 is for file not found in windows

also: if you are recieving nothing at all as output, maybe setting timeout>2 will help.
lunaetic said on jul 6, 2005 at 9:33 am :
to anyone else who is having the "error invoking external ... error =2" problem, keep in mind that cfusion doesn't "understand" your path environment variables.

so you need to specify the absolute path to the executable you want to run, including the extension name.

bad:
c:\convert

good:
c:\program files\convert.exe

hope this helps.
frankhutchings said on nov 8, 2005 at 5:33 am :
upgraded our production server using the 6.1 updater, following that had problems with <cfexecute>.

however, thanks to "annoyed customer said on dec 19, 2004 at 8:28 pm :", using his work around fixed the problem.

"<cfexecute name="#abspath('bin/shell')#" arguments="#cmd#" timeout=100></cfexecute>

<cfsavecontent variable="result">
<cfexecute name="#abspath('bin/shell')#" arguments="#cmd#" timeout=100>
</cfexecute>
</cfsavecontent>"

thanks mr annoyed!

 

rss feed | send me an e-mail when comments are added to this page | comment report

current page: http://livedocs.adobe.com/coldfusion/6.1/htmldocs/tags-p25.htm