From 851f61719985651e769f8df8246d5ddb855cc022 Mon Sep 17 00:00:00 2001 From: Aleksandr Vinokurov Date: Thu, 8 Nov 2012 13:59:12 +0400 Subject: Fix deep list argument error under Windows in os:cmd/1 Because of leeway in implementing os:cmd/1 under different OS there is a difference in results when calling it with deep list argument. os:cmd/1 specifies io_lib:chars() type for its argument and io_lib functions can produce deep lists inspite of io_lib:chars() result type specification. This commit flattens the argument for erlang:open_port/2 (which is used under Windows) and expands the os_SUITE to regress the bug. --- lib/kernel/src/os.erl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lib/kernel/src/os.erl') diff --git a/lib/kernel/src/os.erl b/lib/kernel/src/os.erl index 742c000cc1..2bded77fc4 100644 --- a/lib/kernel/src/os.erl +++ b/lib/kernel/src/os.erl @@ -187,11 +187,14 @@ cmd(Cmd) -> {unix, _} -> unix_cmd(Cmd); {win32, Wtype} -> - Command = case {os:getenv("COMSPEC"),Wtype} of + Command0 = case {os:getenv("COMSPEC"),Wtype} of {false,windows} -> lists:concat(["command.com /c", Cmd]); {false,_} -> lists:concat(["cmd /c", Cmd]); {Cspec,_} -> lists:concat([Cspec," /c",Cmd]) end, + %% open_port/2 awaits string() in Command, but io_lib:chars() can be + %% deep lists according to io_lib module description. + Command = lists:flatten(Command0), Port = open_port({spawn, Command}, [stream, in, eof, hide]), get_data(Port, []) end. -- cgit v1.2.3