Skip to content

Commit 44431bb

Browse files
committed
Fixex #141 - passes args to script.
This approach concats args (if any passed) with a space delimiter and then appends that to the scriptpath (space separed) and used AddScript() which takes this combination of script and args.
1 parent d4aec5f commit 44431bb

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,22 @@ protected async Task HandleLaunchRequest(
9797

9898
await editorSession.PowerShellContext.ExecuteCommand(setWorkingDirCommand);
9999

100-
Logger.Write(LogLevel.Verbose, "Working dir set to '" + workingDir + "'");
100+
Logger.Write(LogLevel.Verbose, "Working dir set to: " + workingDir);
101+
102+
// Prepare arguments to the script - if specified
103+
string arguments = null;
104+
if ((launchParams.Args != null) && (launchParams.Args.Length > 0))
105+
{
106+
arguments = string.Join(" ", launchParams.Args);
107+
Logger.Write(LogLevel.Verbose, "Script arguments are: " + arguments);
108+
}
101109

102110
// Execute the given PowerShell script and send the response.
103111
// Note that we aren't waiting for execution to complete here
104112
// because the debugger could stop while the script executes.
105113
Task executeTask =
106114
editorSession.PowerShellContext
107-
.ExecuteScriptAtPath(launchParams.Program)
115+
.ExecuteScriptAtPath(launchParams.Program, arguments)
108116
.ContinueWith(
109117
async (t) => {
110118
Logger.Write(LogLevel.Verbose, "Execution completed, terminating...");

src/PowerShellEditorServices/Session/PowerShellContext.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,16 +432,22 @@ public async Task<IEnumerable<object>> ExecuteScriptString(
432432
/// Executes a script file at the specified path.
433433
/// </summary>
434434
/// <param name="scriptPath">The path to the script file to execute.</param>
435+
/// <param name="arguments">Arguments to pass to the script.</param>
435436
/// <returns>A Task that can be awaited for completion.</returns>
436-
public async Task ExecuteScriptAtPath(string scriptPath)
437+
public async Task ExecuteScriptAtPath(string scriptPath, string arguments = null)
437438
{
438439
// If we don't escape wildcard characters in the script path, the script can
439440
// fail to execute if say the script name was foo][.ps1.
440441
// Related to issue #123.
441442
string escapedScriptPath = EscapeWildcardsInPath(scriptPath);
442443

444+
if (arguments != null)
445+
{
446+
escapedScriptPath += " " + arguments;
447+
}
448+
443449
PSCommand command = new PSCommand();
444-
command.AddCommand(escapedScriptPath);
450+
command.AddScript(escapedScriptPath);
445451

446452
await this.ExecuteCommand<object>(command, true);
447453
}

0 commit comments

Comments
 (0)