From 98e2413e00b9b30f0a613d0f9fdb6180e2bc9b95 Mon Sep 17 00:00:00 2001 From: Yaroslav Maslennikov Date: Fri, 25 Oct 2024 10:21:42 +0200 Subject: [PATCH] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Lukas Backström (FKA Larsson) --- lib/kernel/src/os.erl | 1 + lib/kernel/test/os_SUITE.erl | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/kernel/src/os.erl b/lib/kernel/src/os.erl index 570ddb6cf7f..3f0895167a3 100644 --- a/lib/kernel/src/os.erl +++ b/lib/kernel/src/os.erl @@ -519,6 +519,7 @@ cmd(Cmd) -> -doc """ Executes `Command` in a command shell of the target OS, captures the standard output and standard error of the command, and returns this result as a string. + The command shell can be set using the [kernel configuration parameter](kernel_app.md#os_cmd_shell), by default the shell is detected upon system startup. diff --git a/lib/kernel/test/os_SUITE.erl b/lib/kernel/test/os_SUITE.erl index d5cf6735adb..5899e23b555 100644 --- a/lib/kernel/test/os_SUITE.erl +++ b/lib/kernel/test/os_SUITE.erl @@ -62,7 +62,7 @@ end_per_group(_GroupName, Config) -> Config. init_per_testcase(TC, Config) - when TC =:= background_command; TC =:= close_stdin; TC =:= os_cmd_shell -> + when TC =:= background_command; TC =:= close_stdin -> case os:type() of {win32, _} -> {skip,"Should not work on windows"}; @@ -475,13 +475,15 @@ os_cmd_shell(Config) -> SysShell = filename:join(DataDir, "sys_shell"), {ok, OldShell} = application:get_env(kernel, os_cmd_shell), - application:set_env(kernel, os_cmd_shell, SysShell), - - %% os:cmd should not try to detect the shell location rather than use - %% the value from kernel:os_cmd_shell parameter - Ls = os:cmd("ls"), - application:set_env(kernel, os_cmd_shell, OldShell), - comp("sys_shell", Ls). + try + application:set_env(kernel, os_cmd_shell, SysShell), + + %% os:cmd should not try to detect the shell location rather than use + %% the value from kernel:os_cmd_shell parameter + comp("sys_shell", os:cmd("ls")) + after + application:set_env(kernel, os_cmd_shell, OldShell), + end. no_limit_for_opened_files() -> case os:type() of