PowerShell在同一会话中执行.bat文件

时间:2016-11-15 10:40:03

标签: powershell batch-file

我正在使用PowerShell以静默方式安装软件。安装成功完成但是当我尝试执行几个批处理文件时,我遇到了一些例外。

  

无法找到给定模式的文件。系统找不到指定的路径。

我在PowerShell中的命令:

$inst_path = \\My installed drive (c:\program files\mysoftware\)
& $inst_path\start-service.bat install

但是当我关闭PowerShell ISE并执行相同的命令时,它没有任何例外,所以有人可以帮助我克服这个问题吗?

1 个答案:

答案 0 :(得分:2)

你在bat文件的路径中有一个双斜杠,$inst_path变量和你构造的路径。

您正试图致电c:\program files\mysoftware\\start-service.bat - 这将失败。

请改为尝试:

$inst_path = "c:\program files\mysoftware"
& "$inst_path\start-service.bat" install
相关问题