user1075715
user1075715

Reputation: 71

Translating command call from CMD batch into PowerShell

I am working on translating a program written as a CMD batch file into PowerShell and ran into the below code snippet. I am unsure on how to translate this into PowerShell. I am particularly interested in translating line 1 (2>NUL 1>NUL) and line 2 (errorlevel 1).

If you were writing this entire code snippet in PowerShell how would you do it and why.

Could someone please help? Thanks.

"C:\Program Files (x86)\erl5.8.5\erts-5.8.5\bin\erlsrv" list RabbitMQ 2>NUL 1>NUL
if errorlevel 1 (
"C:\Program Files (x86)\erl5.8.5\erts-5.8.5\bin\erlsrv" add RabbitMQ
)

Upvotes: 1

Views: 393

Answers (1)

dplante
dplante

Reputation: 2449

  1. per http://ss64.com/nt/syntax-redirection.html

2>NUL and 1>nul means redirect all standard output and error output to null

  1. if errorlevel 1

should translate into someting like:

if ($LASTEXITCODE eq 1)

Upvotes: 1

Related Questions