how to suppress exit 0?

You can redirect the output and save it in a variable, then have condition to spit or not.

$Output = & cmd /c "openPS.bat script2.ps1 $($someParam[-1])" *>&1

#use $Output variable and take decisions.
*>&1 redirects all stream output to output stream.

[quote quote=141049][/quote]
i used variable as you said and then i used this if statement:
<p class=“lang-bsh prettyprint prettyprinted”>if($output) -match “0”){Out-Null}
</p>
it didnt do anything. its still outpututting exit code 0

I would reiterate what @Olaf-Soyk said. You have to understand some basics. Atleast you should read help documentation of Out-Null cmdlet to understand why we are asking you go grab the basics.

[quote quote=141150]I would reiterate what @olaf-soyk said. You have to understand some basics. Atleast you should read help documentation of Out-Null cmdlet to understand why we are asking you go grab the basics.

[/quote]
But…I went per your recommendation…variable…condition…out-null…

Where is the issue?

Without you showing the complete code you’re using including the code of the batch file we have barely enough information to help you.

if($output) -match "0"){Out-Null}

The above code is syntactically wrong. Do one step at a time. See what is there in the output for each execution. Based on the output, put some logic to exclude printing the output. Still please read the Docs for what ever cmdlets you approach.

Get-Help Out-Null -Online

Here is complete code:

$Output = & cmd /c "openPS.bat script2.ps1 $($someParam[-1])" *>&1

#use $Output variable and take decisions.

If($output -match "0"){out-null}

[quote quote=141169]Here is complete code:[/quote]

If($output -match “0”){out-null}

what if the output is “10”? !!! It would still match “0”

What will out-null do alone. Please read the doc and understand how to use Out-Null.

try

($Output.exception.message -join “”) -match ‘Exit Code: 0’

You have to read the doc !

I mean that will never be the case, but sure, I’ll accept that as long as it suppresses 0

That’s not the point … let it be “01” then … the point is - technically it does not make any sense to use -match in this case. It will result in unpredictable or enexpected results.

Ok, so I should use -eq?