示例#1
0
文件: Spawn.cs 项目: eeejay/gtk-sharp
        public static bool SpawnAsync(string working_directory, string[] argv, string[] envp, SpawnFlags flags, SpawnChildSetupFunc child_setup, out Process child_process)
        {
            int pid;
            IntPtr error;
            IntPtr native_dir = Marshaller.StringToPtrGStrdup (working_directory);
            IntPtr[] native_argv = Marshaller.StringArrayToNullTermPointer (argv);
            IntPtr[] native_envp = Marshaller.StringArrayToNullTermPointer (envp);
            SpawnChildSetupWrapper wrapper = new SpawnChildSetupWrapper (child_setup);
            bool result;

            if (Global.IsWindowsPlatform)
                result = g_spawn_async_utf8 (native_dir, native_argv, native_envp, (int) flags, wrapper.NativeCallback, wrapper.Data, out pid, out error);
            else
                result = g_spawn_async (native_dir, native_argv, native_envp, (int) flags, wrapper.NativeCallback, wrapper.Data, out pid, out error);

            child_process = new Process (pid);
            Marshaller.Free (native_dir);
            Marshaller.Free (native_argv);
            Marshaller.Free (native_envp);
            if (error != IntPtr.Zero) throw new GLib.GException (error);
            return result;
        }
示例#2
0
文件: Spawn.cs 项目: eeejay/gtk-sharp
        public static bool SpawnAsyncWithPipes(string working_directory, string[] argv, string[] envp, SpawnFlags flags, SpawnChildSetupFunc child_setup, out Process child_process, ref int stdin, ref int stdout, ref int stderr)
        {
            int pid;
            IntPtr error;
            IntPtr native_dir = Marshaller.StringToPtrGStrdup (working_directory);
            IntPtr[] native_argv = Marshaller.StringArrayToNullTermPointer (argv);
            IntPtr[] native_envp = Marshaller.StringArrayToNullTermPointer (envp);
            SpawnChildSetupWrapper wrapper = new SpawnChildSetupWrapper (child_setup);
            IntPtr in_ptr = stdin == IgnorePipe ? IntPtr.Zero : Marshal.AllocHGlobal (4);
            IntPtr out_ptr = stdout == IgnorePipe ? IntPtr.Zero : Marshal.AllocHGlobal (4);
            IntPtr err_ptr = stderr == IgnorePipe ? IntPtr.Zero : Marshal.AllocHGlobal (4);
            bool result;

            if (Global.IsWindowsPlatform)
                result = g_spawn_async_with_pipes_utf8 (native_dir, native_argv, native_envp, (int) flags, wrapper.NativeCallback, wrapper.Data, out pid, in_ptr, out_ptr, err_ptr, out error);
            else
                result = g_spawn_async_with_pipes (native_dir, native_argv, native_envp, (int) flags, wrapper.NativeCallback, wrapper.Data, out pid, in_ptr, out_ptr, err_ptr, out error);

            child_process = new Process (pid);
            if (in_ptr != IntPtr.Zero) {
                stdin = Marshal.ReadInt32 (in_ptr);
                Marshal.FreeHGlobal (in_ptr);
            }
            if (out_ptr != IntPtr.Zero) {
                stdout = Marshal.ReadInt32 (out_ptr);
                Marshal.FreeHGlobal (out_ptr);
            }
            if (err_ptr != IntPtr.Zero) {
                stderr = Marshal.ReadInt32 (err_ptr);
                Marshal.FreeHGlobal (err_ptr);
            }
            Marshaller.Free (native_dir);
            Marshaller.Free (native_argv);
            Marshaller.Free (native_envp);
            if (error != IntPtr.Zero) throw new GLib.GException (error);
            return result;
        }