【问题标题】:Why does this work in ISE but not when launched from a batch file?为什么这在 ISE 中有效,但从批处理文件启动时无效?
【发布时间】:2014-07-26 17:13:03
【问题描述】:

如果我在 Powershell ISE 中运行此脚本,它可以工作,但是当它从批处理文件启动时,它就不起作用。脚本是here(clicky)。启动它的批处理文件是here(clicky)

当从批处理文件启动时,powershell 写入 (0) 并且它不起作用。从 ISE 启动时,powershell 会写入 (1),然后运行。

另外,我确实确认脚本正在运行,但不正确。

提前谢谢你!

【问题讨论】:

    标签: batch-file powershell powershell-ise


    【解决方案1】:

    您似乎在双引号引用脚本的路径。另外,为什么要使用 PowerShell 启动另一个 PowerShell 来调用文件?试试:

    @ECHO OFF
    SET ThisScriptsDirectory=%~dp0
    SET PowerShellScriptPath="%ThisScriptsDirectory%\data\Start.ps1"
    PowerShell -ExecutionPolicy Bypass -File %PowerShellScriptPath%
    

    【讨论】:

    • 我将其用作批处理文件,然后调用 Powershell 文件。这做同样的事情,但在批处理窗口而不是 powershell 窗口中。
    • 为什么这是一件坏事?唯一的区别是它使用 cmd 窗口(顺便说一句,powershell 窗口是相同的控制台,只有蓝色背景),直到脚本完成。如果您想在单独的窗口中运行它,请使用start /wait PowerShell -ExecutionPolicy Bypass -File %PowerShellScriptPath%PowerShell.exe 启动速度慢且占用大量资源,因此您希望创建尽可能少的进程。
    • 详情?有没有错误?如果是这样,请将它们包括在您的问题中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-15
    • 1970-01-01
    • 1970-01-01
    • 2014-04-24
    • 2011-03-12
    • 2015-09-12
    相关资源
    最近更新 更多