windows - 无法使用 `call` 或 `start` 使用 BATCH 启动 ps1 文件
问题描述
我遇到了一个批处理命令的问题,它不会启动我要做的任何事情,即使使用call
不会启动它。
:choice2
set /P c1="text here [Y/N]? "
if /I "%c1%" EQU "Y" start "" /wait /high /max "Powershell.exe -executionpolicy remotesigned -File %batdir%batch\filename.ps1"
if /I "%c1%" EQU "N" goto :end
goto :choice2
主要要求是 %batdir% 在第一if
行,因为批处理从闪存驱动器运行。
没有尝试过%batdir%
,无论哪种方式都行不通。尝试对powershell.exe使用不同的命令,尝试使用直接dir
的powershell,不起作用,总是得到“找不到文件,确保它输入正确。”。
我将不胜感激任何人都可以提供的帮助。
解决方案
由于您没有提供Minimal Complete and Verifiable Example,因此假定这%batdir%
是正在运行的批处理文件的位置,我已将其替换为适当的%~dp0
变量。您还应该注意,我还替换了您的set /p
命令,因为这不是用于已知单键输入的正确命令:
:choice2
"%SystemRoot%\System32\choice.exe" /M "text here"
If ErrorLevel 2 GoTo end
Start "" /Wait /High /Max "%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -ExecutionPolicy RemoteSigned -File "%~dp0batch\filename.ps1"
GoTo choice2
:end
Pause
我不推荐使用/High
or/Max
来完成这个任务,(包括他们只是因为你做了)。因此,因为您说您也尝试过call
,所以在我看来,您可能也不需要使用start
这些选项。如果只需要运行powershell脚本并等待它完成,在返回输入提示之前,试试这个修改:
:choice2
"%SystemRoot%\System32\choice.exe" /M "text here"
If ErrorLevel 2 GoTo end
"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -ExecutionPolicy RemoteSigned -File "%~dp0batch\filename.ps1"
GoTo choice2
:end
Pause
推荐阅读
- javascript - 是否可以使用 DocFlavor.BYTE_ARRAY.AUTOSENSE 在 npm 中的打印机上打印字节数组,就像在 java 中一样
- itext - 仅更改特定文本颜色 + itext
- python - 在迭代列表时,将值和接下来的 2 个值添加到新列表中
- mysql - 如何在 MySQL 中递归查找父级的子级
- java - 是否可以遍历 lambda 表达式中的数组?(爪哇)
- javascript - 存储在 FileList 中的图像未在 React 中显示
- php - 将标签更改为在 WordPress 上使用 DOMDocument
- python - 从图像中裁剪圆形缩略图的最简单方法是什么?
- ajax - 如何通过ajax获取typo3表单框架表单html
- python - 如果 D 在另一个数据集中的两个列之间,则获取 C col