Preventing output from external commands within `New-PSUEndpoint`

I have an endpoint that executes openssl.exe, certutil.exe and certreq.exe; these commands produce output; which I am piping either to Out-Null or assigning to variables.

However, for some reason, whenever I run openssl.exe req -newkey rsa:4096 -nodes -keyout -config openssl.cnf -out request.csr; I cannot prevent the text Generating a RSA private key [...] writing new private key to [...] from being returned as a response of the endpoint. Which means my endpoint always ends up with responsecode 400

Even when I explicitly define a new-PSUApiResponse it still chokes on the output of openssl.exe

Is there any way to avoid this (maybe with a flag for New-PSUEndpoint to disregard any output other than New-PSUApiResponse?)?

Product: PowerShell Universal
Version: 2.5.3

try this…

openssl.exe req -newkey rsa:4096 -nodes -keyout -config openssl.cnf -out request.csr 2>&1 | out-null

I’m guessing this is to do with the difference in output streams, since some of the output is being muted by out-null, the output that currently isnt will be in a different stream and you need to redirect that.
https://ss64.com/nt/syntax-redirection.html

Should probably have added all the methods that I tried already :slight_smile:

I tried 2>&1 | Out-Null yet it still ends up in the returned value of the endpoint :frowning: (While running the exact same command outside of PSU; it will suppress output as expected)

Let me also share how I’m testing this:

Try {
    Invoke-RestMethod -Uri http://localhost:5000/foo/bar -method Post -UseBasicParsing -Headers @{ 'X-foo-token' = 'Bearer bar' }
}
Catch {
    $StreamReader = [System.IO.StreamReader]::New($_.Exception.Response.GetResponseStream())
    $ErrResp = $StreamReader.ReadToEnd()
    $StreamReader.Close()
}

$ErrResp

This returns:

**Actual expected returned value here**
Generating a RSA private key
at <ScriptBlock>, <No file>: line 88
at <ScriptBlock>, <No file>: line 1
...++++
at <ScriptBlock>, <No file>: line 88
at <ScriptBlock>, <No file>: line 1
.............................++++
at <ScriptBlock>, <No file>: line 88
at <ScriptBlock>, <No file>: line 1
writing new private key to 'C:\foo.key'
at <ScriptBlock>, <No file>: line 88
at <ScriptBlock>, <No file>: line 1
-----
at <ScriptBlock>, <No file>: line 88
at <ScriptBlock>, <No file>: line 1

Hmm, actually I think something else is going wrong here; I was put on the wrong track here because I forgot $ErrResp = $Null duh
Disregard this thread :smiley: