简体   繁体   English

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

[英]Run a batch file in an externam CMD window from PowerShell

I have a PowerShell script that runs on startup and creates a couple of batch files. 我有一个在启动时运行并创建几个批处理文件的PowerShell脚本。 I need to create the batch files (as opposed to run them directly) as they are required for use by users at a later time. 我需要创建批处理文件(而不是直接运行它们),因为以后用户需要使用它们。

This PowerShell script should then run each of these batch files in there own CMD window, as these CMD windows will persist until the server is shutdown. 然后,此PowerShell脚本应在自己的CMD窗口中运行这些批处理文件中的每一个,因为这些CMD窗口将一直存在,直到服务器关闭。

While I can get a new CMD window to appear for each batch file, I can't seem to get them to run my batch files. 虽然可以为每个批处理文件显示一个新的CMD窗口,但似乎无法让它们运行我的批处理文件。 What am I doing wrong? 我究竟做错了什么?

###
 # 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"

Try this 尝试这个

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM