Frage

In Windows Powershell, I want to make a script that runs a bunch of commands in succession.

Like so:

mongo a.js > aout.txt
mongo b.js > bout.txt
...

I'm using PowerShell to get access to the linux like > command. But I can't figure out how to easily write this script. I assume it's trivial. I tried writing a batch script but that doesn't work, due to > isn't supported.

How would you do it?

War es hilfreich?

Lösung

Create a file with a .ps1 extension. Put this in the file:

param($path = $pwd)
mongo $path\a.js > $path\aout.txt
mongo $path\b.js > $path\bout.txt

The above assumes mongo is in your path. Now make sure you have execution policy set to allow scripts to run. Execute this in PowerShell (running as admin):

Set-ExecutionPolicy RemoteSigned # you can also use Unrestricted if you'd like

Then execute your script e.g.:

C:\> C:\mymongo\mongo-it.ps1 C:\mymongo
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top