I'm trying to convert this windows .BAT file (which runs a Client & Server networked code app) into Powershell :
我正在尝试将此Windows .BAT文件(运行客户端和服务器网络代码应用程序)转换为Powershell:
Here is my bat file :
这是我的bat文件:
@echo off
setlocal
start cmd
start java FixedMessageSequenceServer
ping 192.0.2.2 -n 1 -w 5000 > null
start /wait java FixedMessageSequenceClient
if errorlevel 1 goto retry
echo Finished successfully
exit
:retry
echo retrying...
start /wait java BatchWakeMeUpSomehow
Here is my Powershell file :
这是我的Powershell文件:
Start-Job -ScriptBlock {
& java FixedMessageSequenceServer
Start-Sleep -s 1
& java FixedMessageSequenceClient
}
Start-Sleep -s 1
But when I try to run, it doesn't output correctly or do anything. I'm also not sure how to convert the start /wait
.
但是当我尝试运行时,它无法正确输出或执行任何操作。我也不确定如何转换开始/等待。
1 个解决方案
#1
2
The start
external call operator in cmd is roughly equivalent to Start-Process
(alias start
) in PowerShell - it even has a -Wait
parameter.
cmd中的start外部调用操作符大致相当于PowerShell中的Start-Process(别名start) - 它甚至具有-Wait参数。
Start-Job
on the other hand launches your scriptjob in a background process.
另一方面,Start-Job在后台进程中启动scriptjob。
Start-Process java FixedMessageSequenceServer
Start-Sleep -Seconds 1
$JavaClient = Start-Process java FixedMessageSequenceClient -Wait -PassThru
if($JavaClient.ExitCode)
{
# exit code is non-zero, better retry
Start-Process java BatchWakeMeUpSomehow -Wait
}
#1
2
The start
external call operator in cmd is roughly equivalent to Start-Process
(alias start
) in PowerShell - it even has a -Wait
parameter.
cmd中的start外部调用操作符大致相当于PowerShell中的Start-Process(别名start) - 它甚至具有-Wait参数。
Start-Job
on the other hand launches your scriptjob in a background process.
另一方面,Start-Job在后台进程中启动scriptjob。
Start-Process java FixedMessageSequenceServer
Start-Sleep -Seconds 1
$JavaClient = Start-Process java FixedMessageSequenceClient -Wait -PassThru
if($JavaClient.ExitCode)
{
# exit code is non-zero, better retry
Start-Process java BatchWakeMeUpSomehow -Wait
}