enabled hash bang support, fixed run scripts to not alter the current working directory

This commit is contained in:
Peter Honeder committed 2015-07-31 00:47:22 +02:00
1 parent 56ae9e5ebd
commit f2fd9ca303
10 files changed
+90 -27

No files matched your search

+31 -13
View File
@@ -109,28 +109,46 @@ namespace Microsoft.Samples.PowerShell.Host
private static void ManagedMain(string[] args)
{
// Display the welcome message.
Console.WriteLine();
Console.WriteLine("PowerShell for Linux interactive console");
Console.WriteLine("========================================");
Console.WriteLine();
Console.WriteLine("Current status:");
Console.WriteLine("- Type 'exit' to exit");
Console.WriteLine("- Utility and Management cmdlet modules are loadable");
Console.WriteLine();
String initialScript = null;
if (args.Length > 0 && args[0] == "--file")
if (args.Length > 0)
{
initialScript = File.ReadAllText(args[1]);
for (int i = 0; i < args.Length; ++i)
{
string arg = args[i];
bool hasNext = (i+1)<args.Length;
string nextArg = hasNext ? args[i+1] : "";
if (hasNext && arg == "--file")
{
initialScript = File.ReadAllText(nextArg);
++i;
}
else if (hasNext && arg == "--working-dir")
{
Directory.SetCurrentDirectory(nextArg);
++i;
}
}
}
// Create the listener and run it. This method never returns.
// Create the listener and run it
PSListenerConsoleSample listener = new PSListenerConsoleSample(initialScript);
// only run if there was no script file passed in
if (initialScript == null)
{
// Display the welcome message.
Console.WriteLine();
Console.WriteLine("PowerShell for Linux interactive console");
Console.WriteLine("========================================");
Console.WriteLine();
Console.WriteLine("Current status:");
Console.WriteLine("- Type 'exit' to exit");
Console.WriteLine("- Utility and Management cmdlet modules are loadable");
Console.WriteLine();
listener.Run();
}
}
/// <summary>
+22 -1
View File
@@ -9,6 +9,7 @@ using System.Management.Automation.Host;
using System.Globalization;
using System.Reflection;
using System.Runtime.InteropServices;
using System.IO;
namespace ps_hello_world
{
@@ -534,7 +535,27 @@ namespace ps_hello_world
allArgs.Add(argv[i]);
}
test2(allArgs.ToArray());
List<string> filteredArgs = new List<string>();
if (allArgs.Count > 0)
{
for (int i = 0; i < allArgs.Count; ++i)
{
string arg = allArgs[i];
bool hasNext = (i+1)<allArgs.Count;
string nextArg = hasNext ? allArgs[i+1] : "";
if (hasNext && arg == "--working-dir")
{
Console.WriteLine("working dir set to: " + nextArg);
Directory.SetCurrentDirectory(nextArg);
++i;
}
else
filteredArgs.Add(arg);
}
}
test2(filteredArgs.ToArray());
return 0;
}