diff --git a/scripts/3rdparty/hashbang/README.txt b/scripts/3rdparty/hashbang/README.txt new file mode 100644 index 0000000000..c5f97f0aa1 --- /dev/null +++ b/scripts/3rdparty/hashbang/README.txt @@ -0,0 +1,8 @@ +Usage: + +PATH=$PATH:/absolute/path/to/powershell/app_base ./script.ps1 + +Comment: + +The script assumes that /usr/bin/env can execute runps-file.sh. + diff --git a/scripts/3rdparty/hashbang/script.ps1 b/scripts/3rdparty/hashbang/script.ps1 new file mode 100755 index 0000000000..d9c86695b0 --- /dev/null +++ b/scripts/3rdparty/hashbang/script.ps1 @@ -0,0 +1,5 @@ +#!/usr/bin/env runps-file.sh + +get-process +get-module + diff --git a/scripts/Makefile b/scripts/Makefile index ebb1ca27b8..07df6de115 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -183,11 +183,14 @@ run-file: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-release-clr pester-tests: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-release-clr # execute the pester tests, pester needs a TEMP environment variable to be set - exec_env/app_base/runps-simple.sh 'cd ../../../src/pester-tests; $$env:TEMP="/tmp"; invoke-pester' + exec_env/app_base/runps-simple.sh 'cd ../src/pester-tests; $$env:TEMP="/tmp"; invoke-pester' test: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-release-clr $(addprefix $(TESTRUN_FOLDER)/, ps_test.dll xunit.console.netcore.exe xunit.runner.utility.dll xunit.abstractions.dll xunit.execution.dll) pester-tests dotnetlibs/monad_native cd exec_env/app_base && PSMODULEPATH=$(shell pwd)/exec_env/app_base/Modules LD_LIBRARY_PATH=../coreclr:. ../coreclr/corerun xunit.console.netcore.exe ps_test.dll -xml ../../xunittests.xml + # run the c++ tests cd dotnetlibs && ./monad_native + # test the 3rdparty/hashbang sample + PATH=$(PATH):$(shell pwd)/exec_env/app_base 3rdparty/hashbang/script.ps1 run-debugclr: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-debug-clr PAL_DBG_CHANNELS="+LOADER.TRACE" exec_env/app_base/runps-simple.sh get-location diff --git a/scripts/runps-file.sh b/scripts/runps-file.sh new file mode 100755 index 0000000000..e3239ccdc8 --- /dev/null +++ b/scripts/runps-file.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +SCRIPTDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) + +"$SCRIPTDIR/runps.sh" --file "$@" + diff --git a/scripts/runps-simple-debug.sh b/scripts/runps-simple-debug.sh index 75b105ff00..6bbe7a82d5 100755 --- a/scripts/runps-simple-debug.sh +++ b/scripts/runps-simple-debug.sh @@ -1,8 +1,9 @@ #!/bin/bash +CWD=$(pwd) SCRIPTDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) -cd $SCRIPTDIR -echo "launching PS now" -PSMODULEPATH=$SCRIPTDIR/Modules LD_LIBRARY_PATH=.:/usr/lib/llvm-3.6/lib lldb-3.6 ./host_cmdline -- -c ../coreclr -alc Microsoft.PowerShell.CoreCLR.AssemblyLoadContext.dll -tpa powershell-simple.exe "powershell-simple, version=1.0.0.0, culture=neutral, PublicKeyToken=null" "ps_hello_world.Program" "UnmanagedMain" "$@" +cd "$SCRIPTDIR" +echo "launching PS debug now" +PSMODULEPATH="$SCRIPTDIR/Modules" LD_LIBRARY_PATH="$SCRIPTDIR:/usr/lib/llvm-3.6/lib" lldb-3.6 ./host_cmdline -- -c ../coreclr -alc Microsoft.PowerShell.CoreCLR.AssemblyLoadContext.dll -tpa powershell-simple.exe "powershell-simple, version=1.0.0.0, culture=neutral, PublicKeyToken=null" "ps_hello_world.Program" "UnmanagedMain" --working-dir "$CWD" "$@" diff --git a/scripts/runps-simple-trace.sh b/scripts/runps-simple-trace.sh index 33d1c0e33c..d8e08c031a 100755 --- a/scripts/runps-simple-trace.sh +++ b/scripts/runps-simple-trace.sh @@ -1,8 +1,9 @@ #!/bin/bash +CWD=$(pwd) SCRIPTDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) -cd $SCRIPTDIR -echo "launching PS now" -PSMODULEPATH=$SCRIPTDIR/Modules LD_LIBRARY_PATH=. strace -e trace=file ./host_cmdline -c ../coreclr -alc Microsoft.PowerShell.CoreCLR.AssemblyLoadContext.dll -tpa powershell-simple.exe "powershell-simple, version=1.0.0.0, culture=neutral, PublicKeyToken=null" "ps_hello_world.Program" "UnmanagedMain" "$@" +cd "$SCRIPTDIR" +echo "launching PS trace now" +PSMODULEPATH="$SCRIPTDIR/Modules" LD_LIBRARY_PATH="$SCRIPTDIR" strace -e trace=file ./host_cmdline -c ../coreclr -alc Microsoft.PowerShell.CoreCLR.AssemblyLoadContext.dll -tpa powershell-simple.exe "powershell-simple, version=1.0.0.0, culture=neutral, PublicKeyToken=null" "ps_hello_world.Program" "UnmanagedMain" --working-dir "$CWD" "$@" diff --git a/scripts/runps-simple.sh b/scripts/runps-simple.sh index 31d2c7d183..214fc64652 100755 --- a/scripts/runps-simple.sh +++ b/scripts/runps-simple.sh @@ -1,8 +1,8 @@ #!/bin/bash +CWD=$(pwd) SCRIPTDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) -cd $SCRIPTDIR -echo "launching PS now" -PSMODULEPATH=$SCRIPTDIR/Modules LD_LIBRARY_PATH=. ./host_cmdline -c ../coreclr -alc Microsoft.PowerShell.CoreCLR.AssemblyLoadContext.dll -tpa powershell-simple.exe "powershell-simple, version=1.0.0.0, culture=neutral, PublicKeyToken=null" "ps_hello_world.Program" "UnmanagedMain" "$@" +cd "$SCRIPTDIR" +PSMODULEPATH="$SCRIPTDIR/Modules" LD_LIBRARY_PATH="$SCRIPTDIR" ./host_cmdline -c ../coreclr -alc Microsoft.PowerShell.CoreCLR.AssemblyLoadContext.dll -tpa powershell-simple.exe "powershell-simple, version=1.0.0.0, culture=neutral, PublicKeyToken=null" "ps_hello_world.Program" "UnmanagedMain" --working-dir "$CWD" "$@" diff --git a/scripts/runps.sh b/scripts/runps.sh index 8e54219550..5f672c053f 100755 --- a/scripts/runps.sh +++ b/scripts/runps.sh @@ -1,8 +1,8 @@ #!/bin/bash +CWD=$(pwd) SCRIPTDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) -cd $SCRIPTDIR -echo "launching PS now" -PSMODULEPATH=$SCRIPTDIR/Modules LD_LIBRARY_PATH=. ./host_cmdline -c ../coreclr -alc Microsoft.PowerShell.CoreCLR.AssemblyLoadContext.dll -tpa powershell-run.exe "powershell-run, version=1.0.0.0, culture=neutral, PublicKeyToken=null" "Microsoft.Samples.PowerShell.Host.PSListenerConsoleSample" "UnmanagedMain" "$@" +cd "$SCRIPTDIR" +PSMODULEPATH="$SCRIPTDIR/Modules" LD_LIBRARY_PATH="$SCRIPTDIR" ./host_cmdline -c ../coreclr -alc Microsoft.PowerShell.CoreCLR.AssemblyLoadContext.dll -tpa powershell-run.exe "powershell-run, version=1.0.0.0, culture=neutral, PublicKeyToken=null" "Microsoft.Samples.PowerShell.Host.PSListenerConsoleSample" "UnmanagedMain" --working-dir "$CWD" "$@" diff --git a/src/powershell-run/main.cs b/src/powershell-run/main.cs index 0bb3990538..1deea32139 100644 --- a/src/powershell-run/main.cs +++ b/src/powershell-run/main.cs @@ -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) diff --git a/src/powershell-run/powershell-simple.cs b/src/powershell-run/powershell-simple.cs index e9909a92bf..ca0b393589 100644 --- a/src/powershell-run/powershell-simple.cs +++ b/src/powershell-run/powershell-simple.cs @@ -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 filteredArgs = new List(); + if (allArgs.Count > 0) + { + for (int i = 0; i < allArgs.Count; ++i) + { + string arg = allArgs[i]; + bool hasNext = (i+1)