Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I Get command exit code executed with Testcontainers?

Using GenericContainer#execInContainer I can only get stdout or stderr.

Is there any way to get exit code of executed command?

I can't rely on the presence of text in stderr. The application I execute prints some info to stderr but exits with code 0.

like image 876
Kirill Avatar asked Sep 22 '26 22:09

Kirill


2 Answers

execInContainer is just a shortcut to execCreateCmd/execStartCmd from docker-java. Unfortunately, their API doesn't provide a way to get the exit code.

But you can make use of built-in shell functionality and just return the code as part of stdout/stderr:

$ sh -c 'false; echo "ExitCode=$?"'
ExitCode=1

where false is your command

like image 138
bsideup Avatar answered Sep 24 '26 14:09

bsideup


You can use inspectExecCmd(execId) to get information about the executed command, and also you can get exit code from the response of inspectExecCmd

like image 24
Andrew Mazurok Avatar answered Sep 24 '26 14:09

Andrew Mazurok



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!