# Cross-platform way to handle cmd in hxml

**URL:** <https://community.haxe.org/t/cross-platform-way-to-handle-cmd-in-hxml/1097>\
**Category:** Haxe\
**Tags:** hxml\
**Created:** [September 19, 2018, 4:30pm UTC](https://community.haxe.org/t/cross-platform-way-to-handle-cmd-in-hxml/1097 "2018-09-19T16:30:45Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![pinkboi](https://community.haxe.org/user_avatar/community.haxe.org/pinkboi/32/2416_2.png) [@pinkboi](https://community.haxe.org/u/pinkboi)\
**Post date:** [September 19, 2018, 4:30pm UTC](https://community.haxe.org/t/cross-platform-way-to-handle-cmd-in-hxml/1097/1 "2018-09-19T16:30:45Z")

</div>

I want to have haxe run a command after it has compiled it. But even if I run haxe from, say, git bash it still uses the standard windows shell to run any commands specified in the .hxml (which makes sense). Unfortunately the Windows command-line doesn’t like the unix slashes, at least not when specifying executable.

Note that this isn’t a problem with running js and probably not with other scripting languages (it’s ultimately up to the interpreter itself, which is going to be smart) so this works linux, windows, mac:

`-cmd node bin/tests.js`

However if I want to run something that has been build as a binary executable (using cpp or hl + cl) it won’t work cross-platform:

`-cmd ./bin/tests/RunTests` (works in unixen)  
`-cmd .\\bin\\tests\\RunTests` (works in Windows)

I know there are other workarounds if I use wrappers, etc. but is there a simple way just through editing the hxml to handle both types of slashes? Or to switch by platform? I see some really old examples of using macros to accomplish this but again involves adding entire files and doesn’t work for me in haxe 4.

---

<div class="post-metadata">

**Author:** ![ebishton](https://community.haxe.org/user_avatar/community.haxe.org/ebishton/32/15_2.png) [@ebishton](https://community.haxe.org/u/ebishton)\
**Post date:** [September 19, 2018, 8:39pm UTC](https://community.haxe.org/t/cross-platform-way-to-handle-cmd-in-hxml/1097/2 "2018-09-19T20:39:04Z")

</div>

Set the COMSPEC (or ComSpec) environment variable to the path of GitBash or whatever it is you want Windows to use as your command line when it runs system commands.

---

<div class="post-metadata">

**Author:** ![pinkboi](https://community.haxe.org/user_avatar/community.haxe.org/pinkboi/32/2416_2.png) [@pinkboi](https://community.haxe.org/u/pinkboi)\
**Post date:** [September 26, 2018, 5:00pm UTC](https://community.haxe.org/t/cross-platform-way-to-handle-cmd-in-hxml/1097/4 "2018-09-26T17:00:09Z")

</div>

I don’t want devs to have to set an environment variable just to use this and I don’t want git bash to be a requirement, particularly when I’m not using any fancy shell features, I’m simply calling an executable. The only requirement should be the haxe compiler.

---

<div class="post-metadata">

**Author:** ![ianharrigan](https://community.haxe.org/user_avatar/community.haxe.org/ianharrigan/32/52_2.png) [@ianharrigan](https://community.haxe.org/u/ianharrigan)\
**Post date:** [September 26, 2018, 9:17pm UTC](https://community.haxe.org/t/cross-platform-way-to-handle-cmd-in-hxml/1097/5 "2018-09-26T21:17:41Z")

</div>

I hit a similar problem, this seems to work:

```haxe
-cmd ./bin/tests
-cmd RunTests

```

something like that should work, this is what im using:

```haxe
-cmd cd build/android
-cmd gradlew build -x lint

```

Ian

---

<div class="post-metadata">

**Author:** ![pinkboi](https://community.haxe.org/user_avatar/community.haxe.org/pinkboi/32/2416_2.png) [@pinkboi](https://community.haxe.org/u/pinkboi)\
**Post date:** [September 27, 2018, 2:18pm UTC](https://community.haxe.org/t/cross-platform-way-to-handle-cmd-in-hxml/1097/6 "2018-09-27T14:18:52Z")

</div>

I think you meant to include a `cd` in the first one. That does work in Windows (but so does the way I said earlier, using \ instead of /), but doesn’t work in mac or linux. If I include `./` then it works in linux and mac but not Windows. I also have other reasons for wanting to select by os than just the slashes issue.

---

<div class="post-metadata">

**Author:** ![Gama11](https://community.haxe.org/user_avatar/community.haxe.org/gama11/32/7_2.png) [@Gama11](https://community.haxe.org/u/Gama11)\
**Post date:** [September 27, 2018, 2:38pm UTC](https://community.haxe.org/t/cross-platform-way-to-handle-cmd-in-hxml/1097/7 "2018-09-27T14:38:21Z")

</div>

You might be able to simply use `--cwd` instead of `-cmd cd`.

---

<div class="post-metadata">

**Author:** ![ianharrigan](https://community.haxe.org/user_avatar/community.haxe.org/ianharrigan/32/52_2.png) [@ianharrigan](https://community.haxe.org/u/ianharrigan)\
**Post date:** [September 27, 2018, 2:52pm UTC](https://community.haxe.org/t/cross-platform-way-to-handle-cmd-in-hxml/1097/8 "2018-09-27T14:52:51Z")

</div>

Right, gotcha, i thought it was just a slash issue

---

<div class="post-metadata">

**Author:** ![AdrianV](https://community.haxe.org/user_avatar/community.haxe.org/adrianv/32/152_2.png) [@AdrianV](https://community.haxe.org/u/AdrianV)\
**Post date:** [September 28, 2018, 8:31am UTC](https://community.haxe.org/t/cross-platform-way-to-handle-cmd-in-hxml/1097/9 "2018-09-28T08:31:28Z")

</div>

why not write a hx file which does what you want and call it with:

-cmd haxe -main AfterCompile --interp

---

<div class="post-metadata">

**Author:** ![matan](https://community.haxe.org/user_avatar/community.haxe.org/matan/32/206_2.png) [@matan](https://community.haxe.org/u/matan)\
**Post date:** [September 28, 2018, 9:05am UTC](https://community.haxe.org/t/cross-platform-way-to-handle-cmd-in-hxml/1097/10 "2018-09-28T09:05:55Z")

</div>

Slightly related, I’ve adapted a `haxex` script that allows you easily execute haxe as a shell script. Check it out here: [haxex, a short shell script that can be used so you have Haxe shell scripting · GitHub](https://gist.github.com/Matan/85273fc592950f9aae8d143857013c21)

---

<div class="post-metadata">

**Author:** ![pinkboi](https://community.haxe.org/user_avatar/community.haxe.org/pinkboi/32/2416_2.png) [@pinkboi](https://community.haxe.org/u/pinkboi)\
**Post date:** [September 28, 2018, 1:50pm UTC](https://community.haxe.org/t/cross-platform-way-to-handle-cmd-in-hxml/1097/11 "2018-09-28T13:50:16Z")

</div>

I was hoping to avoid having to do that, but at this point I think that’s the only reliable way to do it right. I’ll just make a general purpose class that does nothing but call an arbitrary executable with whatever command-line arguments.

---

<div class="post-metadata">

**Author:** ![pinkboi](https://community.haxe.org/user_avatar/community.haxe.org/pinkboi/32/2416_2.png) [@pinkboi](https://community.haxe.org/u/pinkboi)\
**Post date:** [September 28, 2018, 1:51pm UTC](https://community.haxe.org/t/cross-platform-way-to-handle-cmd-in-hxml/1097/12 "2018-09-28T13:51:20Z")

</div>

Doesn’t solve the problem. Note what I said about `./`
