我正在尝试制作一个简单的脚本来设置我的 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/