# Run under cmd.exe?

**URL:** https://travis-ci.community/t/run-under-cmd-exe/1811
**Category:** Windows
**Created:** [January 12, 2019, 3:25pm UTC](https://travis-ci.community/t/run-under-cmd-exe/1811 "2019-01-12T15:25:24Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![theory](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/theory/32/948_2.png) [@theory](https://travis-ci.community/u/theory)
#### Post date: [January 12, 2019, 3:25pm UTC](https://travis-ci.community/t/run-under-cmd-exe/1811/1 "2019-01-12T15:25:24Z")

</div>

Is it possible to run under `cmd.exe` rather than git-bash? Or is it best to wait for the PowerShell variant to ship?

I know PowerShell is available, but not being a Windows person, it’s not clear to me how to switch. If I just run

```
- powershell

```

My build hangs.

---

<div class="post-metadata">

### Author: ![yancouto](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/yancouto/32/1001_2.png) [@yancouto](https://travis-ci.community/u/yancouto)
#### Post date: [January 18, 2019, 12:23am UTC](https://travis-ci.community/t/run-under-cmd-exe/1811/2 "2019-01-18T00:23:59Z")

</div>

I managed to get this working by running it through Make (with `SHELL=cmd`). Probably not the best way but it works. Check [this commit](https://github.com/uspgamedev/luasteam/commit/7592a6fc0d591e66b1d47e24f1bd6e290ae9b346) for how I did it.

---

<div class="post-metadata">

### Author: ![apjanke](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/apjanke/32/1064_2.png) [@apjanke](https://travis-ci.community/u/apjanke)
#### Post date: [January 28, 2019, 6:04am UTC](https://travis-ci.community/t/run-under-cmd-exe/1811/3 "2019-01-28T06:04:50Z")

</div>

You can run `cmd.exe` or PowerShell commands by sticking them in `.bat` or `.ps1` scripts and calling those from the Travis `script`, as long as you don’t mind the scripts running as a single job step.

For `cmd.exe` stuff: Put your commands in a .bat script file and call the .bat file as a command from the main script. Git bash is smart enough to run that under `cmd.exe`.

```auto
script:
  - my_cmd_script.bat

```

For PowerShell, you need to enable script execution, and then you can call `.ps` scripts with `PowerShell -File <file>`.

```auto
install:
  - PowerShell -Command 'Set-ExecutionPolicy -ExecutionPolicy RemoteSigned'

script:
  - PowerShell -File my_powershell_script.ps1

```

You can also run single PowerShell commands using `PowerShell -Command <command>` from the script. You will probably need to put `<command>` in single quotes to get bash escaping right.

I think calling `powershell` without any arguments will fire up an interactive PowerShell session, which is why your build hangs.

Example: [https://travis-ci.com/apjanke/travis-octave-windows/builds/98765078](https://travis-ci.com/apjanke/travis-octave-windows/builds/98765078)

I’d suggest writing your scripts in PowerShell instead of .bat files, even if you’re not familiar with it, because .bat is the worst scripting language ever invented.

---

<div class="post-metadata">

### Author: ![theory](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/theory/32/948_2.png) [@theory](https://travis-ci.community/u/theory)
#### Post date: [January 30, 2019, 4:17pm UTC](https://travis-ci.community/t/run-under-cmd-exe/1811/4 "2019-01-30T16:17:54Z")

</div>

> I’d suggest writing your scripts in PowerShell instead of .bat files, even if you’re not familiar with it, because .bat is the worst scripting language ever invented.

LOL.

Anyway, reason I asked is because I thought, based on the docs, that Powershell support was somehow able to be invoked directly from `.travis.yml`, but clearly, at least now, one can’t select or trigger PowerShell context (or `cmd.exe`) for `travis.yml`.

---

<div class="post-metadata">

### Author: ![abdullahtahiriyo](https://avatars.discourse-cdn.com/v4/letter/a/3da27b/32.png) [@abdullahtahiriyo](https://travis-ci.community/u/abdullahtahiriyo)
#### Post date: [April 29, 2019, 5:52pm UTC](https://travis-ci.community/t/run-under-cmd-exe/1811/5 "2019-04-29T17:52:24Z")

</div>

Thanks for the insight.

I have just learned that currently you can do this:

```auto
cmd.exe /C 'MSBuild.exe FreeCAD_Trunk.sln /m:2 /nologo /verbosity:minimal /p:Configuration=Release /p:Platform=x64'

```

Running through cmd.exe has the additional advantage that you do not have to escape forward slashes:

```auto
MSBuild.exe FreeCAD_Trunk.sln //m:2 //nologo //verbosity:minimal //p:Configuration=Release //p:Platform=x64

```
