Skip to content

PowerShell command format error after running first command #388

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
ok3721 opened this issue May 9, 2025 · 0 comments
Open

PowerShell command format error after running first command #388

ok3721 opened this issue May 9, 2025 · 0 comments

Comments

@ok3721
Copy link

ok3721 commented May 9, 2025

Current Behavior

When the environments extension is enabled, whether in venv or not, running first python script is working, but all subsequent run commands are in wrong format, with no '&' at front, and ' ' in python executable path is not escaped, resulting in error.

# first run
PS C:\> & "C:\Users\Spaced Username\AppData\Local\Microsoft\WindowsApps\python3.11.exe" "c:/Users/Spaced Username/Documents/test.py"
# second run
PS C:\> C:\Users\Spaced Username\AppData\Local\Microsoft\WindowsApps\python3.11.exe "c:/Users/Spaced Username/Documents/test.py"
C:\Users\Spaced: The term 'C:\Users\Spaced' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Expected Behavior

# first run
PS C:\> & "C:\Users\Spaced Username\AppData\Local\Microsoft\WindowsApps\python3.11.exe" "c:/Users/Spaced Username/Documents/test.py"
# second run
PS C:\> & "C:\Users\Spaced Username\AppData\Local\Microsoft\WindowsApps\python3.11.exe" "c:/Users/Spaced Username/Documents/test.py"

Possible Solution

I believe src/features/terminal/runInTerminal.ts is involved

    if (terminal.shellIntegration) {
        let execution: TerminalShellExecution | undefined;
        const deferred = createDeferred<void>();
        const disposable = onDidEndTerminalShellExecution((e) => {
            if (e.execution === execution) {
                disposable.dispose();
                deferred.resolve();
            }
        });
        execution = terminal.shellIntegration.executeCommand(executable, allArgs); // also parse command text here?
        await deferred.promise;
    } else {
        const shellType = identifyTerminalShell(terminal);       
        let text = quoteArgs([executable, ...allArgs]).join(' ');      // correct behavior
        if (shellType === ShellConstants.PWSH && !text.startsWith('&')) {
            // PowerShell requires commands to be prefixed with '&' to run them.
            text = `& ${text}`;
        }
        terminal.sendText(`${text}\n`);
    }
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

No branches or pull requests

1 participant