python - 通过一个 ps1 脚本打开两个网络服务器

标签 python powershell

我尝试通过 PowerShell 在单个 ps1 脚本中运行以下命令,希望两个本地服务器在不同端口上打开 - 仅打开 8080:

cd "\\blah\Statistics\Reporting\D3\walkthroughs\letsMakeABarChart" 
python -m http.server 8080

cd "\\foo\data_science\20161002a_d3js\examples" 
python -m http.server 8000 

我可以调整它以便两者都打开吗?

最佳答案

第一个 python 调用可能不会返回,因此您可以使用 Start-Job cmdlet:

$job1 = start-job -scriptblock {
    cd "\\blah\Statistics\Reporting\D3\walkthroughs\letsMakeABarChart" 
    python -m http.server 8080    
}

$job2 = start-job -scriptblock { 
    cd "\\foo\data_science\20161002a_d3js\examples" 
    python -m http.server 8000 
} 

# Wait until both web servers terminates:
Wait-Job -Job ($job1, $job2)

关于python - 通过一个 ps1 脚本打开两个网络服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39996792/

相关文章:

powershell - 如何让 Powershell Invoke-Restmethod 返回 http 500 代码响应正文

powershell - 具有多个值的切换用例

docker 上的 Windows 服务无法启动

python猜数字的问题

python - 在 Python App Engine 中,如何唯一标识在开发 SDK 上运行的应用程序实例?

python - 在 nltk wordnet 中找不到该短语,但通过 Princeton wordnetweb 在线搜索找到

python - 如何在Python3.8中将 `typing.get_type_hints`与PEP585一起使用?

Python - 根据儒略日增量重命名文件

powershell - 如何在每次调用时重建哈希表的特定键?

powershell - 在多个组中使用 Get-ADGroup 和 Get-Groupmember