小编tar*_*a23的帖子

在VSCode中的PowerShell命令提示符中隐藏完整文件路径

因此,我刚刚下载了Visual Studio Code,用作我学习Python的默认IDE。我在64位计算机上运行,​​因此我将默认终端窗口设置为powershell。

我将保存大部分文件的位置是大约8个文件夹,在可以编写任何命令之前,所有文件夹都会显示在终端中。有什么方法可以隐藏或缩短终端中的文件路径?

powershell visual-studio-code

3
推荐指数
1
解决办法
1785
查看次数

使用 Python 3.5 执行 PowerShell 命令

我一直在研究一个需要通过 PowerShell 命令行运行 Python 脚本的问题。脚本应该将命令传递到命令行并保存输出。但是,我遇到了无法识别某些命令行参数的问题。

import subprocess
try:
    output = subprocess.check_output\
    (["Write-Output 'Hello world'"], shell=True)
    # (["dir"], shell=True)
except subprocess.CalledProcessError as e:
    print(e.output)
    print('^Error Output^')
Run Code Online (Sandbox Code Playgroud)

如果我将当前命令与命令一起使用check_output,我会收到一条错误消息,指出:

'"Write-Output 'Hello world'"' is not recognized as an internal or external command,
operable program or batch file.
Run Code Online (Sandbox Code Playgroud)

如果我只使用该"dir"行,脚本运行得很好。我在这里不同意为什么会发生这种情况。这不是我正在运行的确切脚本,但它在我的机器上产生了同样的问题。如果我只是在命令行中输入问题命令,它会"Hello world"按预期输出到新行。

任何有关为什么会发生这种情况的见解将不胜感激。如果相关,我不想使用任何类型的管理员权限解决方法。

python powershell windows-scripting

3
推荐指数
1
解决办法
1808
查看次数