Example #1
0
        public static bool SpawnSync(string working_directory, string[] argv, string[] envp, SpawnFlags flags, SpawnChildSetupFunc child_setup, out string stdout, out string stderr, out int exit_status)
        {
            IntPtr native_stdout, native_stderr, 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_sync(native_dir, native_argv, native_envp, (int)flags, wrapper.NativeCallback, wrapper.Data, out native_stdout, out native_stderr, out exit_status, out error);
            }
            else
            {
                result = g_spawn_sync(native_dir, native_argv, native_envp, (int)flags, wrapper.NativeCallback, wrapper.Data, out native_stdout, out native_stderr, out exit_status, out error);
            }

            Marshaller.Free(native_dir);
            Marshaller.Free(native_argv);
            Marshaller.Free(native_envp);
            stdout = Marshaller.PtrToStringGFree(native_stdout);
            stderr = Marshaller.PtrToStringGFree(native_stderr);
            if (error != IntPtr.Zero)
            {
                throw new GLib.GException(error);
            }
            return(result);
        }
Example #2
0
        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);
        }
Example #3
0
        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);
        }
Example #4
0
 public Variant(string[] strv)
 {
     IntPtr[] native = Marshaller.StringArrayToNullTermPointer(strv);
     handle = g_variant_ref_sink(g_variant_new_strv(native, new IntPtr((long)strv.Length)));
     Marshaller.Free(native);
 }