Eiffel:我如何进行系统调用?

Eiffel: how do I do a system call?

我想用 bzip2 myFile.bz2 解压缩一个文件,我必须使用哪个 class?

我试图在 base kernel documentation 中找到它,这对我来说最有意义但没有找到它

这个有效:

    make
        local
            l_env:EXECUTION_ENVIRONMENT
        do
            create l_env
            l_env.system ("bzip2 test.txt")
        end

我使用管道 linux 的最终解决方案如下:

feature -- Commands

    piped_command_result (a_command: STRING): detachable PROCESS_COMMAND_RESULT
            -- https://groups.google.com/forum/#!topic/eiffel-users/O9KEtBSPrf4
        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 either "/bin/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

Credits to google groups eiffel users

注意与其他用户一起使用 apache 启动的应用程序,您必须检查您的环境变量和 $PATH 以便它可以工作!