我无法获得powershell脚本来直接执行bat文件。例如,这个工程在命令行上:从Powershell脚本运行BAT文件的最安全方法
.\\my-app\my-fle.bat
当我添加此命令的脚本,它输出:
The term '.\\my-app\my-file.bat' is not recognized as the
name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included,
verify that the path is correct and try again.
我也试过以下,具有相同的结果:
& .\\my-app\my-fle.bat
& ".\\my-app\my-fle.bat"
\my-app\my-fle.bat
& \my-app\my-fle.bat
& "\my-app\my-fle.bat"
注意:它必须返回lastexitcode,因为我需要验证批次的成功。
这工作。这是否也会返回LastExitCode中的退出状态? – cmcginty
要从启动过程访问$ lastexitcode,您需要将命令指定给变量并使用passthru开关,然后从变量读取exitcode。 –