MainSystem Command ExampleSuppose we want to execute the command to determine the version of Java running on your system. You may execute the following command: java -version
Which on my machine results in: java version "1.6.0_03"
Java(TM) SE Runtime Environment (build 1.6.0_03-b05)
Java HotSpot(TM) Client VM (build 1.6.0_03-b05, mixed mode)
Example UsageThe system command object is created using the command: <cfset syscmd = createObject("java","au.com.webcode.util.SystemCommand").init()>
This object has one function: execute(command,timeout). <cfset result = syscmd.execute(command,timeout)>
The parameters are:
Return ValueThe value returned from the execute() function is an object with the following functions:
ExampleA simple example of ColdFusion code to use the system command utility. <cfset command = "java -version">
<cfset syscmd = createObject("java","au.com.webcode.util.SystemCommand").init()>
<cfset result = syscmd.execute(command)>
<cfoutput>
Command: #result.getCommand()#<br />
ExitValue: #result.getExitValue()#<br />
Error Output: #result.getErrorOutput()#<br />
Standard Output: #result.getStandardOutput()#<br />
</cfoutput>
|