Skip to content

Commit aaa8246

Browse files
Copilotbaronfel
andcommitted
Handle CommandArguments-only case where first arg is the command
Co-authored-by: baronfel <573979+baronfel@users.noreply.github.com>
1 parent a03ae45 commit aaa8246

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

src/Tasks/Exec.cs

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -367,21 +367,40 @@ private void CreateTemporaryBatchFile()
367367
if (!string.IsNullOrWhiteSpace(Command))
368368
{
369369
sw.Write(Command);
370-
}
371370

372-
// Append command arguments if provided
373-
if (CommandArguments != null && CommandArguments.Length > 0)
371+
// Append command arguments if provided
372+
if (CommandArguments != null && CommandArguments.Length > 0)
373+
{
374+
foreach (string arg in CommandArguments)
375+
{
376+
sw.Write(' ');
377+
if (NativeMethodsShared.IsUnixLike)
378+
{
379+
sw.Write(EscapeArgumentForUnix(arg));
380+
}
381+
else
382+
{
383+
sw.Write(EscapeArgumentForWindows(arg));
384+
}
385+
}
386+
}
387+
}
388+
else if (CommandArguments != null && CommandArguments.Length > 0)
374389
{
375-
foreach (string arg in CommandArguments)
390+
// If no Command but we have CommandArguments, treat the first argument as the command
391+
// and the rest as arguments
392+
sw.Write(CommandArguments[0]);
393+
394+
for (int i = 1; i < CommandArguments.Length; i++)
376395
{
377396
sw.Write(' ');
378397
if (NativeMethodsShared.IsUnixLike)
379398
{
380-
sw.Write(EscapeArgumentForUnix(arg));
399+
sw.Write(EscapeArgumentForUnix(CommandArguments[i]));
381400
}
382401
else
383402
{
384-
sw.Write(EscapeArgumentForWindows(arg));
403+
sw.Write(EscapeArgumentForWindows(CommandArguments[i]));
385404
}
386405
}
387406
}

0 commit comments

Comments
 (0)