Use "command" to generate file name

I believe this is a bug.
The situation.

I would use the box.json “slug” key to naming my zipped file…

var fileName = command('package show slug').run( returnOutput=true );
cfzip( action="zip", file="")

This raises an error. This:

(From italian: “The file, directory, or volume name syntax is incorrect”)

Evidently the “command()” method returns some “dirty” chars.
I solved it stripped all non-alpha chars, like this:

var slug = REReplace( 
                     command('package show slug').run( returnOutput=true ),

I try to use print.unANSI() without fixing.


Env info:
CommandBox Version: 5.7.0+00653
CFML Engine: Lucee
CFML Version: stable (Gelert)
Java Version: 11.0.11 (AdoptOpenJDK)
JLine Terminal: *
Runwar Version: 4.7.16 (C:\Users\rober\.CommandBox\lib\runwar-4.7.16.jar)

Can you identify what characters are in the output? I would have thought unansi would fix it. You can easily inspect each character by ASCII code in a string like so

		var myString = 'brad	wood ';
		myString.listToArray( '' ).each( (c)=>print.line( '#c# -> #asc(c)#' ) )

Once you determine what the extra chars are, we can figure out where they come from.

I ran your code.

The result:


Should be the last char, code “10”

This is screenshot of mine box.json:


There don’t seem to be any extra characters.

Thanks for support @bdw429s!

Then all you need to do is use trim()!

Technically, this line is the issue: commandbox/show.cfc at development · Ortus-Solutions/commandbox · GitHub

I used print.line() which adds a line break, when I should have just used print.text().

In the early days of CommandBox, all the commands output a line break as part of their final output to separate the prompt, but later on I added a check at the shell level that only adds the line break before drawing the shell if the previous command didn’t output one. I’ve just not made it around to track down all the print.line()s and change them to print.text()s. And when you pipe input like

package show slug | #reverse

or use backtick expansions like

package set name=`package show slug`

CommandBox has always just trimmed those values.

Now, all that said and workaround provided, etc, etc. I would actually recommend you get that information directly from the service layer like so:

component {
	property name='packageService' inject;

	function run() {
		var slug = packageService.readPackageDescriptor( resolvePath( '' ) ).slug;

1 Like

Thanks @bdw429s.
Your accuracy is always so helpful.

1 Like