从 Powershell 脚本运行 BAT 文件的最安全方法 [英] Safest way to run BAT file from Powershell script

查看:59
本文介绍了从 Powershell 脚本运行 BAT 文件的最安全方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法获得直接执行 bat 文件的 powershell 脚本.例如,这适用于命令行:

I can not get a powershell script to execute a bat file directly. For example, this works on the command line:

.\my-appmy-fle.bat

当我将此命令添加到脚本时,它输出:

When I add this command to a script, it outputs:

The term '.\my-appmy-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.

我也尝试了以下方法,结果相同:

I also tried the following, with the same result:

& .\my-appmy-fle.bat
& ".\my-appmy-fle.bat"
my-appmy-fle.bat
& my-appmy-fle.bat
& "my-appmy-fle.bat"

注意:它必须返回lastexitcode,因为我需要验证批处理是否成功.

Note: It must return the lastexitcode as I need to verify success of batch.

推荐答案

cmd.exe /c 'my-appmy-file.bat'

这篇关于从 Powershell 脚本运行 BAT 文件的最安全方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆