command_result ("/usr/bin/md5sum /etc/hosts | cut -f1 -d' '")
feature -- Commands
command_result (a_command: STRING): PROCESS_COMMAND_RESULT -- Not working in case of grep local l_process: PROCESS_MISC l_retry_count: INTEGER do create l_process check command_result_attached: attached l_process.output_of_command (a_command, Void) as l_proc_res then Result := l_proc_res-- check-- Result.exit_code = 0-- -- 127 command not found-- end end ensure instance_free: Class rescue if l_retry_count < 3 then l_retry_count := l_retry_count + 1 retry else {SIT_UTIL}.write_error ("command_result error, even after retrying 3 times :" + a_command) end end
command_result_3 (a_cmd: READABLE_STRING_GENERAL): detachable PROCESS_COMMAND_RESULT -- From $Eiffel_19.10/contrib/library/svn/implementation/process_misc.e local pf: BASE_PROCESS_FACTORY p: BASE_PROCESS retried: BOOLEAN dn: detachable READABLE_STRING_32 err,res: STRING err_spec, res_spec: SPECIAL [NATURAL_8] do if not retried then create res.make (0) create err.make (0) create pf-- if a_dir /= Void then-- dn := a_dir.name-- end p := pf.process_launcher_with_command_line (a_cmd, dn) p.set_hidden (True) p.set_separate_console (False) p.redirect_output_to_stream p.redirect_error_to_stream
create res_spec.make_filled (0, 1024) create err_spec.make_filled (0, 1024)
p.launch if p.launched then from until p.has_output_stream_closed or p.has_output_stream_error loop p.read_output_to_special (res_spec) append_special_of_natural_8_to_string_8 (res_spec, res) end
from until p.has_error_stream_closed or p.has_error_stream_error loop p.read_error_to_special (err_spec) append_special_of_natural_8_to_string_8 (err_spec, err) end
p.wait_for_exit create Result.make (p.exit_code, res, err) else check not_launched: False end end else check retried: False end end ensure instance_free: Class rescue retried := True retry end
command_result_2 (a_command: STRING): PROCESS_COMMAND_RESULT local l_base_proc: BASE_PROCESS l_buffer: SPECIAL [NATURAL_8] l_error: STRING do create l_buffer.make_empty (2048) l_base_proc := {BASE_PROCESS_FACTORY}.process_launcher_with_command_line (a_command, Void) l_base_proc.redirect_output_to_stream l_base_proc.redirect_error_to_stream l_base_proc.launch-- l_process.launch l_base_proc.wait_for_exit l_error := ""
if l_base_proc.exit_code = 0 and not l_base_proc.has_output_stream_error then do_nothing else {SIT_UTIL}.write_error ("Error on command " + a_command + " Details:" + "None") check not_happening: False end end create Result.make (l_base_proc.exit_code, l_buffer.to_array.out, l_error) ensure instance_free: class end
--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/eiffel-users/eabe27c1-f64d-4d6b-b44a-d7d73c05a432%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to eiffel...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/eiffel-users/eabe27c1-f64d-4d6b-b44a-d7d73c05a432%40googlegroups.com.
Понедельник, 2 декабря 2019, 19:38 +03:00 от Gachoud Philippe <ph.ga...@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.
Понедельник, 2 декабря 2019, 20:13 +03:00 от Gachoud Philippe <ph.ga...@gmail.com>:
To unsubscribe from this group and stop receiving emails from it, send an email to eiffel-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/eiffel-users/9c8feb38-a27e-4994-8df1-eb9e08b4c2ae%40googlegroups.com.
feature -- Commands
piped_command_result (a_command: STRING): detachable PROCESS_COMMAND_RESULT local l_cmd: READABLE_STRING_32 l_args: ARRAYED_LIST [READABLE_STRING_32] l_proc: like {BASE_PROCESS_FACTORY}.process_launcher l_err, l_res: STRING l_err_spec, l_res_spec: SPECIAL [NATURAL_8] do create l_res.make (0) create l_err.make (0) create l_res_spec.make_filled (0, 1024) create l_err_spec.make_filled (0, 1024)
l_cmd := (create {EXECUTION_ENVIRONMENT}).default_shell if l_cmd.is_empty then l_cmd := {STRING_32} "sh" end create l_args.make (2) l_args.extend ("-c") l_args.extend (a_command)
l_proc := (create {BASE_PROCESS_FACTORY}).process_launcher (l_cmd, l_args, Void) l_proc.set_hidden (True) l_proc.set_separate_console (False) l_proc.redirect_output_to_stream l_proc.redirect_error_to_stream
l_proc.launch check process_launched: l_proc.launched then -- read output from until l_proc.has_output_stream_closed or l_proc.has_output_stream_error loop l_proc.read_output_to_special (l_res_spec) append_special_of_natural_8_to_string_8 (l_res_spec, l_res) end -- read error from until l_proc.has_error_stream_closed or l_proc.has_error_stream_error loop l_proc.read_error_to_special (l_err_spec) append_special_of_natural_8_to_string_8 (l_err_spec, l_err) end
l_proc.wait_for_exit create Result.make (l_proc.exit_code, l_res, l_err) end ensure instance_free: Class end
feature {NONE} -- Implementation
append_special_of_natural_8_to_string_8 (spec: SPECIAL [NATURAL_8]; a_output: STRING) local i,n: INTEGER do from i := spec.lower n := spec.upper until i > n loop a_output.append_code (spec[i]) i := i + 1 end ensure instance_free: Class end
You can use something like that:command: READABLE_STRING_32arguments: ARRAYED_LIST [READABLE_STRING_32]directory: READABLE_STRING_32command := (create {EXECUTION_ENVIRONMENT}).default_shell
if command.is_empty then
command := {STRING_32} "sh"
end
create arguments.make (1)arguments.extend ({STRING_32} "/usr/bin/md5sum /etc/hosts | cut -f1 -d")directory := ...
p := (create {BASE_PROCESS_FACTORY}).process_launcher (command, arguments, directory)...Hope this helps,Alexander Kogtenkov
Понедельник, 2 декабря 2019, 19:38 +03:00 от Gachoud Philippe <ph.g...@gmail.com>:
To unsubscribe from this group and stop receiving emails from it, send an email to eiffel-users+unsubscribe@googlegroups.com.
Gachoud Philippe <ph.ga...@gmail.com>:
piped_command_result ("sleep 20")
piped_command_result ("/bin/bzip2 -d --stdout /tmp/my_file.bz2|/usr/bin/md5sum|/usr/bin/cut -d' ' -f1")
feature -- Commands
piped_command_result (a_command: STRING): detachable PROCESS_COMMAND_RESULT local l_cmd: READABLE_STRING_32 l_args: ARRAYED_LIST [READABLE_STRING_32] l_proc: like {BASE_PROCESS_FACTORY}.process_launcher l_err, l_res: STRING l_err_spec, l_res_spec: SPECIAL [NATURAL_8] do create l_res.make (0) create l_err.make (0) create l_res_spec.make_filled (0, 1024) create l_err_spec.make_filled (0, 1024)
l_cmd := (create {EXECUTION_ENVIRONMENT}).default_shell if l_cmd.is_empty then
l_cmd := {STRING_32} "/bin/bash" -- or "/bin/sh"
To unsubscribe from this group and stop receiving emails from it, send an email to eiffel-users...@googlegroups.com.
Gachoud Philippe <ph.ga...@gmail.com>:
To view this discussion on the web visit https://groups.google.com/d/msgid/eiffel-users/caf1c14c-c5e6-4d76-82fc-d0e0dc484c58n%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/eiffel-users/1602948998.375118363%40f502.i.mail.ru.
Gachoud Philippe <ph.ga...@gmail.com>:
To view this discussion on the web visit https://groups.google.com/d/msgid/eiffel-users/CAB%2BbLA9-0SNFhi7QUmNOxx5yNS0ySAMKAD7QFZBRT3H7ntW9nw%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/eiffel-users/1603035977.183059155%40f518.i.mail.ru.
Gachoud Philippe <ph.ga...@gmail.com>:
To view this discussion on the web visit https://groups.google.com/d/msgid/eiffel-users/CAB%2BbLA_0N21zuds7UUMLd5xnyDizw3tg32bDcb6-dejSbhaa-Q%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/eiffel-users/1603043083.200458867%40f185.i.mail.ru.
Gachoud Philippe <ph.ga...@gmail.com>:
To view this discussion on the web visit https://groups.google.com/d/msgid/eiffel-users/CAB%2BbLA_sqWy1guDbmg%2BNoxbqz2HF%2BaRLTcy2e2J02PTYWCMBYg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/eiffel-users/1603047746.995024486%40f192.i.mail.ru.
To view this discussion on the web visit https://groups.google.com/d/msgid/eiffel-users/5F8D36E8020000A10003C06C%40gwsmtp.uni-regensburg.de.
To view this discussion on the web visit https://groups.google.com/d/msgid/eiffel-users/5F8D7DEB020000A10003C089%40gwsmtp.uni-regensburg.de.