regards
Finnian
Alexandr Naumchev <anau...@gmail.com>:
Finnian Reilly <frei...@gmail.com>:
--
You received this message because you are subscribed to the Google Groups "Eiffel Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to eiffel-users...@googlegroups.com.
Visit this group at https://groups.google.com/group/eiffel-users.
For more options, visit https://groups.google.com/d/optout.
Karsten Heusser <karsten...@gmx.de>:
note description: "[ Abstract notion of a {FW_PROCESS_HELPER}. ]" design: "[ These "helper" features are designed to assist with use of the {PROCESS_IMP} and {PROCESS_FACTORY}. ]"
class FW_PROCESS_HELPER
feature -- Status Report
has_file_in_path (a_name: STRING): BOOLEAN -- `has_file_in_path' as `a_name'? local l_result, l_msg: STRING do l_msg := dos_where_not_found_message.twin l_result := output_of_command ("where " + a_name, ".") Result := not l_result.same_string (l_msg) xor {PLATFORM}.is_unix end
feature -- Basic Operations
last_error: INTEGER
output_of_command (a_command_line: READABLE_STRING_32; a_directory: detachable READABLE_STRING_32): STRING_32 -- `output_of_command' `a_command_line' launched in `a_directory' (e.g. "." = Current directory). require cmd_not_empty: not a_command_line.is_empty dir_not_empty: attached a_directory as al_dir implies not al_dir.is_empty local l_process: BASE_PROCESS l_buffer: SPECIAL [NATURAL_8] l_result: STRING_32 l_args: ARRAY [STRING_32] l_cmd: STRING_32 l_list: LIST [READABLE_STRING_32] do create Result.make_empty l_list := a_command_line.split (' ') l_cmd := l_list [1] if l_list.count >= 2 then create l_args.make_filled ({STRING_32} "", 1, l_list.count - 1) across 2 |..| l_list.count as ic loop l_args.put (l_list [ic.item], ic.item - 1) end end l_process := (create {BASE_PROCESS_FACTORY}).process_launcher (l_cmd, l_args, a_directory) l_process.set_hidden (True) l_process.redirect_output_to_stream l_process.redirect_error_to_same_as_output l_process.launch if l_process.launched then from create l_buffer.make_filled (0, 512) until l_process.has_output_stream_closed or else l_process.has_output_stream_error loop l_buffer := l_buffer.aliased_resized_area_with_default (0, l_buffer.capacity) l_process.read_output_to_special (l_buffer) l_result := converter.console_encoding_to_utf32 (console_encoding, create {STRING_8}.make_from_c_substring ($l_buffer, 1, l_buffer.count)) l_result.prune_all ({CHARACTER_32} '%R') Result.append (l_result) end l_process.wait_for_exit end end
launch_fail_handler (a_result: STRING) do last_error_result := a_result end
last_error_result: detachable STRING
feature -- Status Report: Wait for Exit
is_not_wait_for_exit: BOOLEAN
is_wait_for_exit: BOOLEAN do Result := not is_not_wait_for_exit end
set_do_not_wait_for_exit do is_not_wait_for_exit := True end
set_wait_for_exit do is_not_wait_for_exit := False end
feature {NONE} -- Code page conversion
converter: LOCALIZED_PRINTER -- Converter of the input data into Unicode. once create Result end
console_encoding: ENCODING -- Current console encoding. once Result := (create {SYSTEM_ENCODINGS}).console_encoding end
feature {TEST_SET_BRIDGE} -- Implementation: Constants
DOS_where_not_found_message: STRING = "INFO: Could not find files for the given pattern(s).%N"
end
note description: "[ Tests of {FW_PROCESS_HELPER}. ]" testing: "type/manual"
class FW_PROCESS_HELPER_TEST_SET
inherit EQA_TEST_SET rename assert as assert_old end
EQA_COMMONLY_USED_ASSERTIONS undefine default_create end
TEST_SET_BRIDGE undefine default_create end
feature -- Test routines
set_path_test note warning: "[ This test is a FALSE-POSITIVE! ============================== The setting of the path to include "blah" works only for the brief moment that the external call is in-effect. Otherwise, it does not impact this software. The Eiffel Studio program is able to (apparently) effect the state of the path using ISE_EIFFEL and ISE_LIBRARY as set in the Windows registry (or Linux equal). However, how this is accomplished is unknown to this library author at this time. Until that is discovered, this test will have its assertions commented out. When the solution is know, effect the solution and then rework this test. ]" local l_mock: FW_PROCESS_HELPER l_blah, l_set_blah: STRING do if {PLATFORM}.is_windows then create l_mock assert_32 ("set_blah", not l_mock.output_of_command ("set_path.cmd", ".").is_empty) l_blah := l_mock.output_of_command ("path.cmd", ".") print ("blah: `" + l_blah + "'") -- assert_32 ("has_blah", l_blah.has_substring (";blah")) end end
output_of_where_test local l_mock: FW_PROCESS_HELPER do create l_mock if {PLATFORM}.is_windows then assert_strings_equal ("where", l_mock.DOS_where_not_found_message, l_mock.output_of_command ("where you_wont_find_me.exe", ".")) end end
has_file_test local l_mock: FW_PROCESS_HELPER do create l_mock assert_32 ("not_found", not l_mock.has_file_in_path ("you_wont_find_me.exe")) end
process_helper_tests -- New test routine local l_mock: FW_PROCESS_HELPER l_result: STRING do if {PLATFORM}.is_windows then create l_mock l_result := l_mock.output_of_command ("where notepad.exe", ".") assert_integers_equal ("notepad_length", notepad_where.count, l_result.count) assert_strings_equal ("notepad", notepad_where, l_result) end end
feature {NONE} -- Implementation
notepad_where: STRING = "C:\Windows\System32\notepad.exe%NC:\Windows\notepad.exe%N"
end
'Alexander Kogtenkov' via Eiffel Users <eiffel...@googlegroups.com>: