microsoft / node-pty

Fork pseudoterminals in Node.JS
Other
1.43k stars 232 forks source link

How do I set the start path of powershell? #546

Closed MassMessage closed 2 years ago

MassMessage commented 2 years ago

Environment details

Issue description

As far i know(let me know if you have a better solution) to start powershell in a directory you have to do something like this:

powershell.exe -NoExit -command "& {Set-Location C:\my\path\here}"

Now I'm trying to reproduce this with spawn from node-pty like this:

  const shell = isWindows ? 'powershell.exe' : 'bash';
  const args = !isNullOrEmptyOrWhiteSpaced(shellStartFolder) ?
                ["-command",  `"& {Set-Location ${shellStartFolder}}"`] : [];
  return spawn(shell, args, {
    name: 'xterm-color',
    cols: DefaultTerminalSize.cols,
    rows: DefaultTerminalSize.rows,
    cwd: isWindows ? process.env.USERPROFILE : process.env.HOME,
    env: process.env as INonUndefinedEnv
  });

but pseudo terminal (i'm using xterm.js) end up like this (give shellStartFolder is "C:\\")

image

What am I missing?

MassMessage commented 2 years ago

Well, I just passed it it as cwd argument lol. Didn't come my mind before