box commands using different directory than current working directory

I have installed CommandBox 1.0.0.00135 on Windows 7 in the folder C:\Utilities\CommandBox\box.exe. I then updated my PATH Windows variable to include the CommandBox folder so I could simply type box [action] from the command line.

Something I’ve noticed though is that when I enter commands such as box init, it doesn’t create a box.json file in my current working directory. It instead installs the file in C:\Utilities\CommandBox where CommandBox is installed.

In order to get this to work as I expect, I have to enter the following as separate commands:

box
CommandBox:Commandbox> cd C:\Projects\some-project-folder
CommandBox:Commandbox> init

This is happening for all commands.

Did I setup something wrong or is this by design?

Best,

Grant

Thanks for the report, Grant. I think your expectation is correct. I’ve given less testing to running CommandBox from the OS command line since I like to use it from within its shell where tab completion, etc work.

I put in ticket COMMANDBOX-85 to look into it. We’ll need to test it on Mac and Linux to see if it’s only a Windows thing and then look at how the OS hands off execution to Java.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Thanks Brad!

NP

Also, if you want to help look into this, you can see how the pwd variable is set. (Stands for "print working directory, but really a poor variable name. We should probably rename it to CWD).
Anywhoo, the CWD is set in the init based on variables passed into the init via constructor injection which comes from constants bound in the WireBox config (Yes, CommandBox uses WireBox under the hood!). The config is in CFML/commandbox/system/config/WireBox.cfc and it is the userDir setting which appears to be the use directory pulled from the Java properties. (line 25)

So, basically, the question is when a jar is run from the OS CLI like “java -jar myApp.jar” what properties are available, and which one points to the directory the command is being run from as opposed to the directory where the executable lives? (In Windows, the exe is just a thin wrapper around an executable jar built with Launch4J). Heck, the launch4J docs probably have something on this very thing.

And also, the Java code that runs before the Railo CLI is loaded up and our CFML code starts running can be found here:
https://github.com/Ortus-Solutions/railo-cli/blob/master/src/java/cliloader/LoaderCLIMain.java

You can see an example of how it passes stuff to the CFML code like on line 217 where it sets the incoming arguments into a system property called “cfml.cli.arguments” which is later accessed near the top of /CFML/commandbox/system/BootStrap.cfm. That is what allows you to run one-off single line commands from your OS CLI and it passes the args along to CommandBox for parsing.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Brad,

Found some cool stuff in the docs. http://launch4j.sourceforge.net/docs.html

Looks like launch4j has the variable %OLDPWD% which contains the current working directory that the executable is called from.

What’s very cool is that you can create a box.l4j.ini file in the folder where box.exe lives, and launch4j will pass those arguments to the Java jar.

Here’s the contents of my C:\Utilities\Commandbox\box.l4j.ini file:

Launch4j runtime config

-Duser.dir="%OLDPWD%"

Basically, I’m overriding the user.dir setting with the %OLDPWD% variable provided by launch4j.

Now when I cd into any directory and type box, the command pwd returns the correct folder I’m in. :smiley:

This may just be an issue on Windows. I haven’t confirmed that yet.

Best,

Grant

Interesting stuff. Launch4J builds the exe in the /build/build.xml file starting on line 209 in the build.cli.exe target. There may be a setting that can be used here to override the userDir.







To run the build on Windows, run the box-cli.bat in the root of the repo, choose option 5, type “build.cli.exe” and hit enter. It will download a bunch of dependencies the first time and eventually spit out a box.exe file (among others) in your "dist’ directory. To test it, wipe our your user/.CommandBox folder and run the new .exe and it will extract itself on first run again. Though, unless you’ve actually changed the CFML code, you can just leave your old .CommandBox folder and simply run the new exe.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Brad,

I’ve updated the source and create a pull request for you guys to review.

Best,

Grant

Thanks Grant! I gave it a whirl on my Windows 7 machine and it seems to work great. Pull request has been merged.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com