简体   繁体   English

如何设置powershell的启动路径?

[英]How do I set the start path of powershell?

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,您必须执行以下操作:

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

Now I'm trying to reproduce this with spawn from node-pty like this:现在我正在尝试使用来自node-ptyspawn来重现它,如下所示:

  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:\\" )但是伪终端(我正在使用 xterm.js)最终会像这样(给shellStartFolder"C:\\"

图片

What am I missing?我错过了什么?

As mentioned in the comments, the spawn() function already takes an argument that specifies the initial working directory: cwd .正如评论中提到的, spawn()函数已经接受了一个指定初始工作目录的参数: cwd

  const shell = isWindows ? 'powershell.exe' : 'bash';
  const args = [];

  return spawn(shell, args, {
    name: 'xterm-color',
    cols: DefaultTerminalSize.cols,
    rows: DefaultTerminalSize.rows,
    cwd: isWindows ? (!isNullOrEmptyOrWhiteSpaced(shellStartFolder) ? shellStartFolder : process.env.USERPROFILE) : process.env.HOME,
    env: process.env as INonUndefinedEnv
  });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM