【问题标题】:Run a batch file in an externam CMD window from PowerShell从 PowerShell 在外部 CMD 窗口中运行批处理文件
【发布时间】:2016-08-10 10:52:58
【问题描述】:

我有一个在启动时运行并创建几个批处理文件的 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"

【问题讨论】:

标签: powershell batch-file cmd


【解决方案1】:

试试这个

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

【讨论】:

  • 我刚刚找到了这个,尽管出于我的目的,我将/k/c 相对应。谢谢。
猜你喜欢
  • 2020-05-22
  • 2010-11-08
  • 1970-01-01
  • 2012-06-19
  • 1970-01-01
  • 1970-01-01
  • 2020-11-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多