Reputation: 10792
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?
Upvotes: 0
Views: 1155
Reputation: 201652
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
Upvotes: 1