Esempio n. 1
0
        public uv_process_options_t(Process process, ProcessOptions options)
        {
            if (string.IsNullOrEmpty(options.File))
            {
                throw new ArgumentException("file of processoptions can't be null");
            }
            else
            {
                file = Marshal.StringToHGlobalAnsi(options.File);
            }

            args = alloc(options.Arguments);
            env  = alloc(options.Environment);
            cwd  = Marshal.StringToHGlobalAnsi(options.CurrentWorkingDirectory);

            // all fields have to be set
            flags = 0;
            uid   = 0;
            gid   = 0;

            if (options.Detached)
            {
                flags |= (uint)uv_process_flags.UV_PROCESS_DETACHED;
            }

            if (options.WindowsVerbatimArguments)
            {
                flags |= (uint)uv_process_flags.UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS;
            }

            if (options.UID.HasValue)
            {
                flags |= (uint)uv_process_flags.UV_PROCESS_SETUID;
                uid    = options.GID;
            }

            if (options.GID.HasValue)
            {
                flags |= (uint)uv_process_flags.UV_PROCESS_SETGID;
                gid    = options.GID;
            }

            exit_cb = Marshal.GetFunctionPointerForDelegate(cb);

            stdio_count = (options.Streams == null && !(options.Streams is UVStream[]) ? 0 : options.Streams.Count);
            if (stdio_count == 0)
            {
                stdio = null;
                return;
            }

            stdio = (uv_stdio_container_stream_t *)Marshal.AllocHGlobal(stdio_count * sizeof(uv_stdio_container_stream_t));

            int i = 0;

            if (options.Streams != null)
            {
                foreach (var stream in options.Streams)
                {
                    stdio[i].flags = 0;
                    if (stream != null)
                    {
                        stdio[i].stream = stream.NativeHandle;
                        if ((stream.readable || stream.writeable) && stream is Pipe)
                        {
                            stdio[i].flags |= uv_stdio_flags.UV_CREATE_PIPE;
                            if (stream.readable)
                            {
                                stdio[i].flags |= uv_stdio_flags.UV_READABLE_PIPE;
                            }
                            if (stream.writeable)
                            {
                                stdio[i].flags |= uv_stdio_flags.UV_WRITABLE_PIPE;
                            }
                        }
                        else if (stream is UVStream)
                        {
                            stdio[i].flags |= uv_stdio_flags.UV_INHERIT_STREAM;
                        }
                    }
                    i++;
                }
            }
        }
Esempio n. 2
0
 public static Process Spawn(Loop loop, ProcessOptions options)
 {
     return(Spawn(loop, options, null));
 }
Esempio n. 3
0
 public static Process Spawn(ProcessOptions options)
 {
     return(Spawn(options, null));
 }
Esempio n. 4
0
 public static Process Spawn(ProcessOptions options, Action <Process>?exitCallback)
 {
     return(Spawn(Loop.Constructor, options, exitCallback));
 }
Esempio n. 5
0
 internal Process(Loop loop, ProcessOptions options, Action <Process>?exitCallback)
     : base(loop, HandleType.UV_PROCESS)
 {
     this.exitCallback = exitCallback;
     process_options   = new uv_process_options_t(this, options);
 }