shell - powershell 命令未在 .bat 文件中运行?

标签 shell powershell path

我正在尝试制作一个简单的脚本来设置我的 gcc 变量。作为 .bat 文件。

变量是这样设置的

$env:Path += ";C:\Users\Brett\Compilers\MinGW\bin"

当我将它输入/粘贴到电源 shell 时,它运行得很好。

但是当我粘贴到脚本 myscript.bat 中,并通过 powershell 运行它时,我收到此错误:
C:\Users\Brett\Compilers>"$env:Path += ";C:\Users\Brett\Compilers\MinGW\bin""
The filename, directory name, or volume label syntax is incorrect.
PS C:\Users\Scruffy\Compilers>

最佳答案

PowerShell 是一个独立于 Windows 命令行 (cmd.exe) 的执行环境

如果您想从批处理文件运行 powershell 命令,您需要保存 powershell 脚本 (.ps1) 并将其作为命令行参数传递到 powershell.exe。

例子:

powershell.exe -noexit c:\scripts\test.ps1

More Information is available here on Microsoft TechNet

关于shell - powershell 命令未在 .bat 文件中运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12666568/

相关文章:

linux - 除非我重新保存,否则 Shell 脚本无法检测到其他进程

powershell - 将纪元时间转换为本地时区(以微秒为单位)

powershell - 可以在我的一台(客户端)计算机上执行 Select-AzureRmSubscription,但不能在另一台计算机上执行

android - 读取存储在内存中的 pdf(文件路径无效)

bash - 在 bash 中连接字符串

linux - 在特定键后输出下一个字符(正则表达式)

powershell - 如何在 Powershell 中对 3000 万条 csv 记录进行排序

java - 从相对路径读取/写入文件时出现问题

variables - IntelliJ 更新路径变量

linux - 以升序打印数字的 Shell Bash 脚本