Solved

Coldfusion 10 SystemCommand, cfexecute, .exe

Posted on 2013-01-11
8
1,274 Views
Last Modified: 2013-11-26
I want to run the .exe file, but the hosting block cfexecute

We do not allow the "cfexecute" tag to be enabled on our shared servers for security reasons.

Search for solutions on the Internet, I found a project systemcommand.jar

java -version (Used to test the code)

Example 1 (SystemCommand_1) Code works

<cfset cmd = "java -version">
<cfset runtime = createObject("java", "java.lang.Runtime")>
<cfset process = runtime.getRuntime().exec(cmd)>
<cfdump var="#process#"/>

Open in new window


Download

https://docs.google.com/file/d/0B65h04x-wff-ekFIaEMzOWRveDg/edit

Example 2 (SystemCommand_2)  Code works

http://blog.stannard.net.au/2007/9/21/executing-system-commands-with-coldfusion/

<cfset command = "java -version">
<cfset syscmd = createObject("component","SystemCommand").init()>
<cfset result = syscmd.execute(command)>
<cfdump var="#result#">

Open in new window


Download

https://docs.google.com/file/d/0B65h04x-wff-b3M3dEZaaF9zVnc/edit

Example 3 (SystemCommand_3) Why the code does not work

http://blog.stannard.net.au/2008/03/26/executing-system-commands-with-coldfusion-2/

http://systemcommand.riaforge.org/

https://github.com/joshuairl/SystemCommand

Application.cfc

component output="false" displayname="" {

	this.javaSettings.loadPaths = [expandPath(".\systemcommand.jar")];
	this.javaSettings.loadColdFusionClassPath=false;
	this.javaSettings.reloadOnChange=true;
}		

Open in new window


test.cfm
<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>

Open in new window


Download
https://docs.google.com/file/d/0B65h04x-wff-WWNJYUR5Z0M4LUE/edit
0
Comment
Question by:kali2406
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
8 Comments
 
LVL 52

Expert Comment

by:_agx_
ID: 38768884
Doesn't work how? Please post any error messages you're getting.

We do not allow the "cfexecute" tag to be enabled on our shared servers for security reasons.
..
<cfset process = runtime.getRuntime().exec(cmd)>

I'm surprised that works at all.  cfexecute is simply a wrapper for Runtime.exec. You may not want to plan on this as a long term solution, since your host could easily disable it too ...
0
 
LVL 11

Expert Comment

by:mcnute
ID: 38769604
You can zip your exe up and that will make it possible to be downloaded, unzipped on the clients computer and then execute the exe.
0
 

Author Comment

by:kali2406
ID: 38769835
Fixed downloading

https://docs.google.com/file/d/0B65h04x-wff-Q0VNWG5xUkZxMmM/edit

I want to generate a Web Page Screenshot on my remote server (hosting)
I use the WebKit PhantomJS.exe

Sample pages that use PhantomJS
http://ctrlq.org/screenshots/
http://screener.brachium-system.net/

I want to use to generate screenshots Command System
http://systemcommand.riaforge.org/
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 52

Expert Comment

by:_agx_
ID: 38770832
Can you post the full error message you are getting?
0
 

Author Comment

by:kali2406
ID: 38771986
Object Instantiation Exception.
Class not found: au.com.webcode.util.SystemCommand
 
The error occurred in C:/ColdFusion10/cfusion/wwwroot/SystemCommand_3/test.cfm: line 3

1 :
2 : <cfset command = "java -version">
3 : <cfset syscmd = createObject("java","au.com.webcode.util.SystemCommand").init()>
4 : <cfset result = syscmd.execute(command)>
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 38772993
It's the "reloadOnChange=true" setting. When it's "false", everything's peachy. But change it to true and you get errors. The docs say it _should_ work, but it doesn't (probably a bug).  The only solution I see is to remove that param.  

Important:  javaSettings's are only evaluated once. If you make changes , you  _must_ also do something to force a reload so the changes are applied (like changing the application name)

Works:
    this.name = "NEW application name 1 here";
    ....
    this.javaSettings =
        {
            LoadPaths = [ ExpandPath("./systemcommand.jar") ]
            , LoadColdFusionClassPath = false
      };

Fails:
    this.name = "NEW application name 2 here";
    ....
    this.javaSettings =
        {
            LoadPaths = [ ExpandPath("./systemcommand.jar") ]
            , LoadColdFusionClassPath = false
            , reloadOnChange="true"
      };
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
JavaScript code not working 3 31
Adding 1 the value of input "text" every 3 seconds 5 33
Html split(text) Part2 6 20
Can anyone help me find this preloader? 51 39
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question