Skip to content

TerminalTaskSystem: Fix addtion arguments for string command #251201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dylanchu
Copy link
Contributor

Changes:

  • Default addtional args is set to empty as "/d /c" is only for cmd.exe
  • For cmd.exe: the "/d" argument should always be the first argument if there are other arguments specified in profiles
  • For cmd.exe: argument "/k" from profiles will be ignored as it conflicts with "/c"
  • For msys2.cmd & msys2_shell.cmd: "-c" will be added automatically if not specified in profiles

This should fix #169821.

@dylanchu
Copy link
Contributor Author

@microsoft-github-policy-service agree

}
const combinedShellArgs = this._addExecStringFlags(shellSpecified, basename, shellArgs, platform);
if (windowsShellArgs) {
combinedShellArgs.push('"' + commandLine + '"');
Copy link
Contributor

@anthonykim1 anthonykim1 Jun 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we wanted commandLine to come be BEFORE all of the shell arguments? @dylanchu @meganrogge

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, no, we didn't. The previous code is like this:

const combinedShellArgs = this._addAllArgument(toAdd, shellArgs);
combinedShellArgs.push(commandLine);  // also after other arguments
shellLaunchConfig.args = windowsShellArgs ? combinedShellArgs.join(' ') : combinedShellArgs;

commandLine is the payload command string specified in tasks by command field. To pass it to the executable, we need to put it exactly behind the "execute command from string" flag (i.e. -c, -Command).

Take cmd.exe and nu.exe as examples, we would like the combined result to be

cmd.exe /d /q /c "echo hello"
nu.exe -I . -c "echo hello"

instead of

cmd.exe "echo hello" /d /c 
nu.exe "echo hello" -I . -c
# or
cmd.exe /d /c /q "echo hello" 
nu.exe -c -I . "echo hello"

;)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for explaining this :)

@dylanchu
Copy link
Contributor Author

Looking forward to the approval @anthonykim1 @meganrogge

};
return defaults[basename] || [];
} else {
return ['-c'];
Copy link
Contributor

@anthonykim1 anthonykim1 Jun 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we want to check whether shellSpecified is false like before when we add -c

				if (!shellSpecified) {
 					// Under Mac remove -l to not start it as a login shell.
 					if (platform === Platform.Platform.Mac) {
 						// Background on -l on osx https://github.com/microsoft/vscode/issues/107563
 						// TODO: Handle by pulling the default terminal profile?
 						// const osxShellArgs = this._configurationService.inspect(TerminalSettingId.ShellArgsMacOs);
 						// if ((osxShellArgs.user === undefined) && (osxShellArgs.userLocal === undefined) && (osxShellArgs.userLocalValue === undefined)
 						// 	&& (osxShellArgs.userRemote === undefined) && (osxShellArgs.userRemoteValue === undefined)
 						// 	&& (osxShellArgs.userValue === undefined) && (osxShellArgs.workspace === undefined)
 						// 	&& (osxShellArgs.workspaceFolder === undefined) && (osxShellArgs.workspaceFolderValue === undefined)
 						// 	&& (osxShellArgs.workspaceValue === undefined)) {
 						// 	const index = shellArgs.indexOf('-l');
 						// 	if (index !== -1) {
 						// 		shellArgs.splice(index, 1);
 						// 	}
 						// }
 					}
 					toAdd.push('-c');
 				}
 			}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

VS Code is still adding /d /c to task commands
3 participants