从PowerShell在externam CMD窗口中运行批处理文件

时间:2016-08-10 10:52:58

标签: powershell batch-file cmd

我有一个在启动时运行的PowerShell脚本,并创建了几个批处理文件。我需要创建批处理文件(而不是直接运行它们),因为用户以后需要使用它们。

然后,这个PowerShell脚本应该在自己的CMD窗口中运行每个批处理文件,因为这些CMD窗口将一直存在,直到服务器关闭。

虽然我可以为每个批处理文件显示一个新的CMD窗口,但我似乎无法让它们运行我的批处理文件。我做错了什么?

###
 # Grab the WebDriver folder and the public IP of this server
 ##
$webDriverFolder = "C:\WebDriver"
$WebDriverHubFilePath = "$webDriverFolder\Launch WebDriver Hub.bat"
$WebDriverIENodeFilePath = "$webDriverFolder\Launch WebDriver InternetExplorer Node 1.bat"
$publicIP = (Invoke-WebRequest ifconfig.me/ip).content

###
 # Generate the batch file contents
 ##
$webDriverHubStr = "batch file stuff"
$WebDriverIENodeStr = "different batch file stuff"

###
 # Generate up to date WebDriver batch files (with the correct IP and folder path)
 ##
$webDriverHubStr | Out-File "$WebDriverHubFilePath"
$WebDriverIENodeStr | Out-File "$WebDriverIENodeFilePath"

###
 # Run the commands to launch WebDriver Hub and IE Node 1
 ##
Start-Process cmd.exe "$WebDriverHubFilePath"
Start-Process cmd.exe "$WebDriverIENodeFilePath"

1 个答案:

答案 0 :(得分:2)

试试这个

Start-Process -FilePath cmd.exe -ArgumentList "/c $WebDriverHubFilePath"
Start-Process -FilePath cmd.exe -ArgumentList "/c $WebDriverIENodeFilePath"