Run under cmd.exe?

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.

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 for how I did it.

1 Like

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.

script:
  - my_cmd_script.bat

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

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

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.

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.

Thanks for the insight.

I have just learned that currently you can do this:

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:

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