How to Run CMD in ColdFusion CreateObject

CMD runs the Windows command line from your ColdFusion project. You use the CreateObject class to run the CMD command on a user's computer, but your ColdFusion application must have permissions to run the app from the browser. The user receives a popup for permission, and if the user chooses "Yes," you can run CMD commands on the user's computer from your Web applications.

Instructions

    • 1

      Open the ColdFusion application, then open your Web project to open the project files in the ColdFusion workspace.

    • 2

      Call the CreateObject class to set up a variable that calls the command prompt. The following code assigns the variable "mycmd" to the Windows command prompt:

      <cfset mycmd = createObject("cmd","au.com.webcode.util.SystemCommand").init()>

    • 3

      Run a Windows command line statement on the computer. For instance, the following code retrieves a list of files and directories using the "dir" command and returns the list to the "myfiles" variable:

      <cfset myfiles = mycmd.execute("dir",30)>

      The "30" parameter sets the timeout for the command, so if the command does not run successfully, a timeout error returns.

    • 4

      Display the results. The following ColdFusion code shows how to display the results of the CMD statement:

      <cfoutput>
      List of Directories: #result.getStandardOutput()#<br>
      </cfoutput>

Related Searches:

References

Comments

Related Ads

Featured