cfexecute and spaces
dtsw opened this issue · comments
i try to cfexecute a command with parameters.
The problem i experience: it fails when called through cfexecute. When i run the command on the command line, it is processed correctly by the msend command.
On Command Line the call would look something like: msend -n cell -a EVENT -m "This is a Test" (i use quotes because there are spaces in the Message).
And this is what i tried in my cfc. The cfc function is called with message="This is a Test". The execution fails.
<cffunction name="sendEvent">
<cfargument name="message" required="true" />
<cftry>
<cfexecute
name = "msend"
arguments = "-n cell -a EVENT -m #arguments.message#"
timeout = "5"
variable = "output"
errorVariable = "error">
</cfexecute>
<cfoutput>#output#</cfoutput>
<cfcatch>
<cfoutput>msend failed</cfoutput><cfdump var="#cfcatch#"/>
</cfcatch>
</cftry>
</cffunction>
PS: If i add escaped quotes ("") around #arguments.message#, i get quotes in the target application which is not what i want/need.
If you look at the manual page for the cfexecute tag http://openbd.org/manual/?/tag/CFEXECUTE you'll see that arguments is supposed to be an array of arguments to pass.
The name should be a full path to the executable though, not sure if just the filename will work.
Are you using Linux, Windows, or Mac?
I don't know what msend is, but try this.
<cffunction name="sendEvent">
<cfargument name="message" required="true" />
<cftry>
<cfset args = ["-n", "cell", "-a", "EVENT", "-m", arguments.message]>
<cfexecute
name = "msend"
arguments = args
timeout = "5"
variable = "output"
errorVariable = "error">
</cfexecute>
<cfoutput>#output#</cfoutput>
<cfcatch>
<cfoutput>msend failed</cfoutput>
<cfdump var="#cfcatch#"/>
</cfcatch>
</cftry>
</cffunction>
i can confirm using array works, but the message comes with additional quotes. If arguments.message has no space in it, then no quotes are added. I am running it on Linux 64 Bit (RedHat). Running with just filename works, if binary is found in path, but i also tried with full path to be safe here.
oh i see my issue with quotes is the way Runtime.getRuntime().exec in java works, when parameters are supplied in a String rather than a String[].
Process process = Runtime.getRuntime().exec(new String[] { "echo", "Hello World" });
vs
Process process = Runtime.getRuntime().exec(new String[] { "echo", ""Hello World"" });
Currently in OpenBD cfexecute, the arguments are translated to a single String. May be cfEXECUTECommandRunner could be modified to take the String[] instead of cmd and attr as individuals?
I might take a look at that, but no promises. I haven't dug around in the cfexecute functionality before.
Though feel free to make a pull request if you have improvements :)
ok i will do after installing my tools for git =). btw. the Google Group for OpenBD is not accessible due to spam. Not sure if you are in control of the group? https://groups.google.com/forum/#!forum/openbd
No I'm just an OpenBD enthusiast/contributor, I don't work for CodeArcs, I have no admin powers here or the Google group.
@dtsw unfortunately there was little we could do about that group so we created a new group - https://groups.google.com/forum/#!forum/openbluedragon
resolved with last merge