Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Displaying logs from when calling external commands from a powershell script

In a powershell module there is a class with the following method (here simplified). It simply calls docker to automatically build an image.

Everything works and the image is correctly built. What I cannot understand is why the logs from docker are not printed in the console (as they do if I call the same docker command directly instead of inside a powershell module).

[void] BuildImage() {
    $imageId = ...
    docker build -f ../Dockerfile . -t $imageId
}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You have a void method, it produces no output. If you want to send output to the success stream (stdout), then change the return type to [string[]] and use return:

[string[]] BuildImage() {
    $imageId = ...
    return docker build -f ../Dockerfile . -t $imageId
}

If instead you’re interested in sending the output to the information stream, you can still have your void method but pipe the output from your docker command to Write-Host:

[void] BuildImage() {
    $imageId = ...
    docker build -f ../Dockerfile . -t $imageId 2>&1 |
        Write-Host
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading