added --file parameter to run a script
This commit is contained in:
parent
8e8b5d14d1
commit
0546b02e1c
|
@ -159,6 +159,11 @@ run-interactive: $(POWERSHELL_RUN_TARGETS) dotnetlibs/corerun dotnetlibs/Microso
|
||||||
if ! diff dotnetlibs/corerun $(MONAD_EXT)/coreclr/Release/corerun; then cp -r $(MONAD_EXT)/coreclr/Release/* dotnetlibs; fi
|
if ! diff dotnetlibs/corerun $(MONAD_EXT)/coreclr/Release/corerun; then cp -r $(MONAD_EXT)/coreclr/Release/* dotnetlibs; fi
|
||||||
cd exec_env/app_base && ./runps.sh
|
cd exec_env/app_base && ./runps.sh
|
||||||
|
|
||||||
|
run-file: $(POWERSHELL_RUN_TARGETS) dotnetlibs/corerun dotnetlibs/Microsoft.PowerShell.Commands.Management.dll dotnetlibs/Microsoft.PowerShell.Commands.Utility.dll dotnetlibs/api-ms-win-core-registry-l1-1-0.dll internal-prepare-exec_env
|
||||||
|
# check if corerun is the right one (could be the debug version)
|
||||||
|
if ! diff dotnetlibs/corerun $(MONAD_EXT)/coreclr/Release/corerun; then cp -r $(MONAD_EXT)/coreclr/Release/* dotnetlibs; fi
|
||||||
|
cd exec_env/app_base && ./runps.sh --file $(PSSCRIPT)
|
||||||
|
|
||||||
test: dotnetlibs/ps_test_runner.exe dotnetlibs/corerun dotnetlibs/api-ms-win-core-registry-l1-1-0.dll
|
test: dotnetlibs/ps_test_runner.exe dotnetlibs/corerun dotnetlibs/api-ms-win-core-registry-l1-1-0.dll
|
||||||
cd dotnetlibs && LD_LIBRARY_PATH=. ./corerun ps_test_runner.exe
|
cd dotnetlibs && LD_LIBRARY_PATH=. ./corerun ps_test_runner.exe
|
||||||
|
|
||||||
|
|
|
@ -4,5 +4,5 @@ SCRIPTDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||||
|
|
||||||
cd $SCRIPTDIR
|
cd $SCRIPTDIR
|
||||||
echo "launching PS now"
|
echo "launching PS now"
|
||||||
PSMODULEPATH=$SCRIPTDIR/Modules LD_LIBRARY_PATH=. ./corerun powershell-run.exe
|
PSMODULEPATH=$SCRIPTDIR/Modules LD_LIBRARY_PATH=. ./corerun powershell-run.exe "$@"
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ namespace Microsoft.Samples.PowerShell.Host
|
||||||
using System.Management.Automation.Host;
|
using System.Management.Automation.Host;
|
||||||
using System.Management.Automation.Runspaces;
|
using System.Management.Automation.Runspaces;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.IO;
|
||||||
using PowerShell = System.Management.Automation.PowerShell;
|
using PowerShell = System.Management.Automation.PowerShell;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -95,17 +96,25 @@ namespace Microsoft.Samples.PowerShell.Host
|
||||||
Console.WriteLine("- Type 'exit' to exit");
|
Console.WriteLine("- Type 'exit' to exit");
|
||||||
Console.WriteLine("- Utility and Management cmdlet modules are loadable");
|
Console.WriteLine("- Utility and Management cmdlet modules are loadable");
|
||||||
Console.WriteLine();
|
Console.WriteLine();
|
||||||
//Console.ForegroundColor = oldFg;
|
|
||||||
|
String initialScript = null;
|
||||||
|
if (args.Length > 0 && args[0] == "--file")
|
||||||
|
{
|
||||||
|
initialScript = File.ReadAllText(args[1]);
|
||||||
|
}
|
||||||
|
|
||||||
// Create the listener and run it. This method never returns.
|
// Create the listener and run it. This method never returns.
|
||||||
PSListenerConsoleSample listener = new PSListenerConsoleSample();
|
PSListenerConsoleSample listener = new PSListenerConsoleSample(initialScript);
|
||||||
listener.Run();
|
|
||||||
|
// only run if there was no script file passed in
|
||||||
|
if (initialScript == null)
|
||||||
|
listener.Run();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the PSListenerConsoleSample class.
|
/// Initializes a new instance of the PSListenerConsoleSample class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public PSListenerConsoleSample()
|
public PSListenerConsoleSample(string initialScript)
|
||||||
{
|
{
|
||||||
// Create the host and runspace instances for this interpreter.
|
// Create the host and runspace instances for this interpreter.
|
||||||
// Note that this application does not support console files so
|
// Note that this application does not support console files so
|
||||||
|
@ -115,35 +124,9 @@ namespace Microsoft.Samples.PowerShell.Host
|
||||||
this.myRunSpace = RunspaceFactory.CreateRunspace(this.myHost,iss);
|
this.myRunSpace = RunspaceFactory.CreateRunspace(this.myHost,iss);
|
||||||
this.myRunSpace.Open();
|
this.myRunSpace.Open();
|
||||||
|
|
||||||
// Create a PowerShell object to run the commands used to create
|
// run the initial script
|
||||||
// $profile and load the profiles.
|
if (initialScript != null)
|
||||||
lock (this.instanceLock)
|
executeHelper(initialScript,null);
|
||||||
{
|
|
||||||
this.currentPowerShell = PowerShell.Create();
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
this.currentPowerShell.Runspace = this.myRunSpace;
|
|
||||||
|
|
||||||
/* PSCommand[] profileCommands = Microsoft.Samples.PowerShell.Host.HostUtilities.GetProfileCommands("SampleHost06");
|
|
||||||
foreach (PSCommand command in profileCommands)
|
|
||||||
{
|
|
||||||
this.currentPowerShell.Commands = command;
|
|
||||||
this.currentPowerShell.Invoke();
|
|
||||||
}*/
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
// Dispose the PowerShell object and set currentPowerShell
|
|
||||||
// to null. It is locked because currentPowerShell may be
|
|
||||||
// accessed by the ctrl-C handler.
|
|
||||||
lock (this.instanceLock)
|
|
||||||
{
|
|
||||||
this.currentPowerShell.Dispose();
|
|
||||||
this.currentPowerShell = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
Loading…
Reference in a new issue