예제 #1
0
        public JsonResult Query(JObject data)
        {
            string sort = Request.Params.Get("sort");

            if (sort == null)
            {
                sort = "";
            }
            string order = Request.Params.Get("order");

            if (order == null)
            {
                order = "";
            }

            int      pageIndex = data.Value <int>("page");
            int      pageSize  = data.Value <int>("rows");
            int      pageCount = 0;
            int      totalRows = 0;
            ProcInfo pinfo     = new ProcInfo();

            pinfo.ProcedureName = "vdp_search_breed";
            pinfo.SQL           = "";
            pinfo.Type          = "proc";
            var list = ListDataPager(sort, order, pageIndex, pageSize, out pageCount, out totalRows, pinfo, data);

            return(JsonNet(new { rows = list, total = totalRows }));
        }
예제 #2
0
파일: WeChatController.cs 프로젝트: vdcan/-
        //接受文本消息
        public string TextHandle(XmlDocument xmldoc)
        {
            string  responseContent = "";
            XmlNode ToUserName      = xmldoc.SelectSingleNode("/xml/ToUserName");
            XmlNode FromUserName    = xmldoc.SelectSingleNode("/xml/FromUserName");
            XmlNode Content         = xmldoc.SelectSingleNode("/xml/Content");
            string  ContentText     = "";

            if (Content != null)
            {
                ContentText = Content.InnerText;
            }
            else
            {
                ContentText = xmldoc.InnerText.ToString();
            };

            JObject data = new JObject();

            data["content"]        = ContentText;
            data["from_user_name"] = FromUserName.InnerText;
            data["to_user_name"]   = ToUserName.InnerText;
            ProcInfo pi = new ProcInfo();

            pi.ProcedureName = "vdp_wechat_content";
            pi.Type          = "proc";
            pi.ConnStr       = "app";
            DataSet ds = RunProcedureDataSet(data, pi);

            responseContent = ProcessResult(ds, xmldoc);

            return(responseContent);
        }
예제 #3
0
        private void GenProc(ShaderProgram Program, ProcInfo Proc)
        {
            if (string.Compare(Proc.Name, "main", true) != 0)
            {
                SB.AppendLine($"void {Proc.Name}() {{");

                Ident = "\t";

                GenProcBody(Program, Proc);

                SB.AppendLine("}");
            }
            else
            {
                //TODO: Support other geometry shader types.
                //Currently, only Point Sprites are supported,
                //but some models uses silhouette, and maybe subdivision too.
                SB.AppendLine($"void main() {{");
                SB.AppendLine("\tfor (geo_i = 0; geo_i < 3; geo_i++) {");

                Ident = "\t\t";

                GenProcBody(Program, Proc);

                SB.AppendLine("\t\tEndPrimitive();");
                SB.AppendLine("\t}");
                SB.AppendLine("}");
            }
        }
예제 #4
0
        private ProcInfo GetProcInfo(Process proc)
        {
            try
            {
                var procInfo = new ProcInfo
                {
                    Id        = proc.Id,
                    Name      = proc.ProcessName,
                    Title     = proc.MainWindowTitle,
                    User      = GetUsername(proc.SessionId),
                    StartTime = GetStartTime(proc),
                    Proc      = proc,
                    Command   = GetCommandLine(proc)
                };

                proc.EnableRaisingEvents = true;
                proc.Exited += (s, e) => ProcOnExited(procInfo);

                return(procInfo);
            }
            catch
            {
                return(null);
            }
        }
예제 #5
0
        private void SetVal(ProcInfo proc, string val)
        {
            try
            {
                if (InvokeRequired)
                {
                    BeginInvoke((Action)(() => SetVal(proc, val)));
                    return;
                }

                var objects = lstView.Objects.Cast <ProcInfo>().ToArray();

                for (var i = 0; i < objects.Length; ++i)
                {
                    if (objects[i].Id != proc.Id)
                    {
                        continue;
                    }

                    lstView.Items[i].SubItems[4].Text = val;
                    break;
                }
            }
            catch
            {
                // ignored
            }
        }
예제 #6
0
        /// <summary>
        /// Adds the ProcInfo var to the ListView1
        /// </summary>
        /// <param name="proc">Process to be added</param>
        private void AddItemToListView(ProcInfo proc)
        {
            ListViewItem item = new ListViewItem(new string[] { proc.Name + ".exe", proc.Id.ToString(), proc.Path });

            item.ImageIndex = proc.IconIndex;
            lvwProcesses.Items.Add(item);
        }
예제 #7
0
 private static bool CreateProcess_internal(ProcessStartInfo startInfo,
                                            IntPtr stdin,
                                            IntPtr stdout,
                                            IntPtr stderr,
                                            ref ProcInfo proc_info)
 {
     throw new System.NotImplementedException();
 }
예제 #8
0
파일: Process.cs 프로젝트: zdpdev/mono
        bool StartWithShellExecuteEx(ProcessStartInfo startInfo)
        {
            if (this.disposed)
            {
                throw new ObjectDisposedException(GetType().Name);
            }

            if (!String.IsNullOrEmpty(startInfo.UserName) || (startInfo.Password != null))
            {
                throw new InvalidOperationException(SR.GetString(SR.CantStartAsUser));
            }

            if (startInfo.RedirectStandardInput || startInfo.RedirectStandardOutput || startInfo.RedirectStandardError)
            {
                throw new InvalidOperationException(SR.GetString(SR.CantRedirectStreams));
            }

            if (startInfo.StandardErrorEncoding != null)
            {
                throw new InvalidOperationException(SR.GetString(SR.StandardErrorEncodingNotAllowed));
            }

            if (startInfo.StandardOutputEncoding != null)
            {
                throw new InvalidOperationException(SR.GetString(SR.StandardOutputEncodingNotAllowed));
            }

            // can't set env vars with ShellExecuteEx...
            if (startInfo.environmentVariables != null)
            {
                throw new InvalidOperationException(SR.GetString(SR.CantUseEnvVars));
            }

            ProcInfo procInfo = new ProcInfo();
            bool     ret;

            FillUserInfo(startInfo, ref procInfo);
            try {
                ret = ShellExecuteEx_internal(startInfo, ref procInfo);
            } finally {
                if (procInfo.Password != IntPtr.Zero)
                {
                    Marshal.ZeroFreeBSTR(procInfo.Password);
                }
                procInfo.Password = IntPtr.Zero;
            }
            if (!ret)
            {
                throw new Win32Exception(-procInfo.pid);
            }

            SetProcessHandle(new SafeProcessHandle(procInfo.process_handle, true));
            SetProcessId(procInfo.pid);

            return(ret);
        }
예제 #9
0
        private void TvFamilyTreeSelectedIndexChanged(object sender, EventArgs e)
        {
            if (((ComboBox)sender).SelectedIndex == 0)
            {
                return;
            }
            _tvFamilyTree.Nodes.Clear();
            var spellfamily = (SpellFamilyNames)(((ComboBox)sender).SelectedValue.ToInt32());

            ProcInfo.Fill(_tvFamilyTree, spellfamily);
        }
예제 #10
0
        public static void Test()
        {
            var procInfo = new ProcInfo();

            procInfo.FileMd5  = TUtils.ComputeMd5Hash(@"E:\BimSrv2\gisserver\webapps\gis\1.dwg");
            procInfo.FileName = "1.dwg";
            procInfo.FileUrl  = "http://127.0.0.1:8080/gis/1.dwg";

            var jsonstr = JsonConvert.SerializeObject(procInfo);

            var base64str = TUtils.EncodeForProcInfo(jsonstr);

            TCadProxy.OpenCad(base64str);
        }
예제 #11
0
        private void GenProc(ShaderProgram Program, ProcInfo Proc)
        {
            SB.AppendLine($"void {Proc.Name}() {{");

            Ident = "\t";

            GenProcBody(Program, Proc);

            if (string.Compare(Proc.Name, "main", true) == 0)
            {
                SB.AppendLine($"{Ident}gl_Position = {OutputNames[0]};");
            }

            SB.AppendLine("}");
        }
예제 #12
0
        public MiraDebugger(MiraDevice p_Device, ProcInfo p_ProcInfo)
        {
            // Create a new list to hold our breakpoints
            m_Breakpoints = new List <Breakpoint>();

            // Assign our information
            ProcessInfo = p_ProcInfo;
            Device      = p_Device;

            // Set our debugger to the initial state
            State = DebuggerState.Detach;

            // Create the new UI elements
            m_BreakpointControl = new ucBreakpoints(this);
            m_CallStackControl  = new ucCallStack(this);
        }
예제 #13
0
        public static string GetProcessOwner(int id)
        {
            var result = PidOwner.GetOrAdd(id, processId => new ProcInfo {
                UserName = GetOwner(processId)
            });

            if (DateTime.UtcNow > result.Expire)
            {
                result = new ProcInfo {
                    UserName = GetOwner(id)
                };
                PidOwner[id] = result;
            }

            return(result.UserName);
        }
예제 #14
0
        public ActionResult Detail(string id)
        {
            ViewBag.Message = "Your application description page.";
            ProcInfo pinfo = new ProcInfo();

            pinfo.ProcedureName = "vdp_get_review_detail";
            pinfo.SQL           = "";
            pinfo.Type          = "proc";
            JObject data = new JObject();

            data["id"] = id;
            var d = RunProcedureDataTable(data, pinfo);

            ViewData["DetailData"] = d;

            return(View());
        }
예제 #15
0
파일: Process.cs 프로젝트: zdpdev/mono
 // Note that ProcInfo.Password must be freed.
 private static void FillUserInfo(ProcessStartInfo startInfo, ref ProcInfo procInfo)
 {
     if (startInfo.UserName.Length != 0)
     {
         procInfo.UserName = startInfo.UserName;
         procInfo.Domain   = startInfo.Domain;
         if (startInfo.Password != null)
         {
             procInfo.Password = Marshal.SecureStringToBSTR(startInfo.Password);
         }
         else
         {
             procInfo.Password = IntPtr.Zero;
         }
         procInfo.LoadUserProfile = startInfo.LoadUserProfile;
     }
 }
예제 #16
0
파일: WeChatController.cs 프로젝트: vdcan/-
        public string ImageHandle(XmlDocument xmldoc)
        {
            string  responseContent = "";
            XmlNode ToUserName      = xmldoc.SelectSingleNode("/xml/ToUserName");
            XmlNode FromUserName    = xmldoc.SelectSingleNode("/xml/FromUserName");
            XmlNode MediaId         = xmldoc.SelectSingleNode("/xml/MediaId");
            XmlNode PicUrl          = xmldoc.SelectSingleNode("/xml/PicUrl");

            JObject data      = new JObject();
            string  path      = "\\wechat\\images\\" + FromUserName.InnerText + "\\";
            string  imagepath = path + DateTime.Now.Ticks.ToString() + ".png";

            data["MediaId"]        = MediaId.InnerText;
            data["PicUrl"]         = PicUrl.InnerText;
            data["LocalPicUrl"]    = imagepath.Replace("\\", "/");
            data["from_user_name"] = FromUserName.InnerText;
            data["to_user_name"]   = ToUserName.InnerText;
            ProcInfo pi = new ProcInfo();

            pi.ProcedureName = "vdp_wechat_image";
            pi.Type          = "proc";
            pi.ConnStr       = "app";
            DataSet ds = RunProcedureDataSet(data, pi);

            responseContent = ProcessResult(ds, xmldoc);



            System.Net.WebClient w = new System.Net.WebClient();
            //  Dim p As String = path + "workdir\images\" + userid.ToString + ".jpg"


            string filepath = System.Web.Hosting.HostingEnvironment.MapPath("/");

            if (!System.IO.Directory.Exists(filepath + path))
            {
                System.IO.Directory.CreateDirectory(filepath + path);
            }

            filepath = filepath + imagepath;
            w.DownloadFile(PicUrl.InnerText, filepath);

            return(responseContent);
        }
예제 #17
0
        protected void GenProcBody(ShaderProgram Program, ProcInfo Proc)
        {
            for (IP = Proc.Offset; IP < Proc.Offset + Proc.Length; IP++)
            {
                //Split procedure if a label is found at current address.
                //This is done to support Jump instructions.
                if (IP > Proc.Offset && Labels.ContainsKey(IP))
                {
                    string Name = Labels[IP];

                    AddProc(Name, IP, (Proc.Offset + Proc.Length) - IP);

                    SB.AppendLine($"\t{Name}();");

                    break;
                }

                //Generate current instruction.
                GenInst(Program, SHBin.Executable[IP]);
            }
        }
예제 #18
0
        private static ProcInfo GetProcInfo(ProcMatchCallBack callback)
        {
            ProcInfo procInfo = new ProcInfo();

            IntPtr snap_shot = new IntPtr();

            WinAPI.PROCESSENTRY32 proc_entry = new WinAPI.PROCESSENTRY32();

            snap_shot         = WinAPI.CreateToolhelp32Snapshot(WinAPI.SnapshotFlags.Process, 0);
            proc_entry.dwSize = (uint)Marshal.SizeOf(typeof(WinAPI.PROCESSENTRY32));
            if (WinAPI.Process32First(snap_shot, ref proc_entry) == true)
            {
                while (WinAPI.Process32Next(snap_shot, ref proc_entry) == true)
                {
                    if (callback(proc_entry))
                    {
                        procInfo.name = proc_entry.szExeFile;
                        procInfo.id   = proc_entry.th32ProcessID;

                        IntPtr proc = WinAPI.OpenProcess(
                            WinAPI.ProcessAccessFlags.QueryInformation | WinAPI.ProcessAccessFlags.VirtualMemoryRead,
                            false, (int)proc_entry.th32ProcessID);
                        StringBuilder path = new StringBuilder(256);
                        if (WinAPI.GetModuleFileNameEx(proc, (IntPtr)0, path, 256) <= 0)
                        {
                            path.Clear();
                        }
                        WinAPI.CloseHandle(proc);

                        procInfo.path    = path.ToString();
                        procInfo.preview = GetExeImage(procInfo.path);

                        break;
                    }
                }
            }
            WinAPI.CloseHandle(snap_shot);

            return(procInfo);
        }
예제 #19
0
		public override void OnFailure () {}	// not use this function

		public override IEnumerator OnProcess ( ProcInfo pi )
		{
			string form = "";

			if (OnMakeDataForm (ref form)) 
			{
				OnSuccess (form);
			}
			else
			{
				ComDebug.Log(string.Format("{0}.OnMakeDataForm = false : {1}", this.GetType().ToString(), errorMsg));
				yield break;
			}

			if(string.IsNullOrEmpty(errorMsg) == false)
			{
				ComDebug.Log(string.Format("{0}.OnSuccess = false : {1}", this.GetType().ToString(), errorMsg));
				yield break;
			}

			yield return null;
		}
예제 #20
0
        private void Timer_TimesUp(object sender, System.Timers.ElapsedEventArgs e)
        {
            //w.MyServer = Server;

            ProcInfo pi   = new ProcInfo();
            JObject  data = new JObject();

            pi.ProcedureName = "vdp_get_unsent_email";
            pi.Type          = "proc";
            pi.ConnStr       = "app";
            DataSet ds = w.RunProcedureDataSet(data, pi);

            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                SendEmail(dr["to_email"].ToString(), dr["subject"].ToString(), dr["context"].ToString());
                //tmpestr += string.Format(ReplyType.Message_News_Item, dr["Title"], dr["Description"],
                // dr["PicUrl"],
                // dr["Url"]);
            }
            //pi.ProcedureName = "vdp_get_unsent_message";
            //pi.Type = "proc";
            //pi.ConnStr = "app";
            //DataSet ds = w.RunProcedureDataSet(data, pi);

            //foreach (DataRow dr in ds.Tables[0].Rows)
            //{
            //    w.PostTextMessageToUser(dr["open_id"].ToString(), dr["message"].ToString());
            //    //tmpestr += string.Format(ReplyType.Message_News_Item, dr["Title"], dr["Description"],
            //    // dr["PicUrl"],
            //    // dr["Url"]);

            //}
            // WeChatController w = new WeChatController();
            //    w.PostTextMessageToUser("ojbqdwKTA8VqKpEKoMql01gSK56Y", "test222");
            //到达指定时间5秒触发该事件输出 Hello World!!!!
            //  System.Diagnostics.Debug.WriteLine("Hello World!!!!");
        }
예제 #21
0
파일: Process.cs 프로젝트: zdpdev/mono
 private extern static bool ShellExecuteEx_internal(ProcessStartInfo startInfo, ref ProcInfo procInfo);
예제 #22
0
		static bool Start_noshell (ProcessStartInfo startInfo, Process process)
		{
			var proc_info = new ProcInfo ();

			if (startInfo.HaveEnvVars) {
				string [] strs = new string [startInfo.EnvironmentVariables.Count];
				startInfo.EnvironmentVariables.Keys.CopyTo (strs, 0);
				proc_info.envKeys = strs;

				strs = new string [startInfo.EnvironmentVariables.Count];
				startInfo.EnvironmentVariables.Values.CopyTo (strs, 0);
				proc_info.envValues = strs;
			}

			MonoIOError error;
			IntPtr stdin_read = IntPtr.Zero, stdin_write = IntPtr.Zero;
			IntPtr stdout_read = IntPtr.Zero, stdout_write = IntPtr.Zero;
			IntPtr stderr_read = IntPtr.Zero, stderr_write = IntPtr.Zero;

			try {
				if (startInfo.RedirectStandardInput) {
					CreatePipe (out stdin_read, out stdin_write, true);
				} else {
					stdin_read = MonoIO.ConsoleInput;
					stdin_write = IntPtr.Zero;
				}

				if (startInfo.RedirectStandardOutput) {
					CreatePipe (out stdout_read, out stdout_write, false);
				} else {
					stdout_read = IntPtr.Zero;
					stdout_write = MonoIO.ConsoleOutput;
				}

				if (startInfo.RedirectStandardError) {
					CreatePipe (out stderr_read, out stderr_write, false);
				} else {
					stderr_read = IntPtr.Zero;
					stderr_write = MonoIO.ConsoleError;
				}

				FillUserInfo (startInfo, ref proc_info);

				//
				// FIXME: For redirected pipes we need to send descriptors of
				// stdin_write, stdout_read, stderr_read to child process and
				// close them there (fork makes exact copy of parent's descriptors)
				//
				if (!CreateProcess_internal (startInfo, stdin_read, stdout_write, stderr_write, ref proc_info)) {
					throw new Win32Exception (-proc_info.pid, 
					"ApplicationName='" + startInfo.FileName +
					"', CommandLine='" + startInfo.Arguments +
					"', CurrentDirectory='" + startInfo.WorkingDirectory +
					"', Native error= " + Win32Exception.W32ErrorMessage (-proc_info.pid));
				}
			} catch {
				if (startInfo.RedirectStandardInput) {
					if (stdin_read != IntPtr.Zero)
						MonoIO.Close (stdin_read, out error);
					if (stdin_write != IntPtr.Zero)
						MonoIO.Close (stdin_write, out error);
				}

				if (startInfo.RedirectStandardOutput) {
					if (stdout_read != IntPtr.Zero)
						MonoIO.Close (stdout_read, out error);
					if (stdout_write != IntPtr.Zero)
						MonoIO.Close (stdout_write, out error);
				}

				if (startInfo.RedirectStandardError) {
					if (stderr_read != IntPtr.Zero)
						MonoIO.Close (stderr_read, out error);
					if (stderr_write != IntPtr.Zero)
						MonoIO.Close (stderr_write, out error);
				}

				throw;
			} finally {
				if (proc_info.Password != IntPtr.Zero) {
					Marshal.ZeroFreeBSTR (proc_info.Password);
					proc_info.Password = IntPtr.Zero;
				}
			}

			process.process_handle = proc_info.process_handle;
			process.pid = proc_info.pid;
			
			if (startInfo.RedirectStandardInput) {
				//
				// FIXME: The descriptor needs to be closed but due to wapi io-layer
				// not coping with duplicated descriptors any StandardInput write fails
				//
				// MonoIO.Close (stdin_read, out error);

#if MOBILE
				var stdinEncoding = Encoding.Default;
#else
				var stdinEncoding = Console.InputEncoding;
#endif
				process.input_stream = new StreamWriter (new FileStream (stdin_write, FileAccess.Write, true, 8192), stdinEncoding) {
					AutoFlush = true
				};
			}

			if (startInfo.RedirectStandardOutput) {
				MonoIO.Close (stdout_write, out error);

				Encoding stdoutEncoding = startInfo.StandardOutputEncoding ?? Console.Out.Encoding;

				process.output_stream = new StreamReader (new FileStream (stdout_read, FileAccess.Read, true, 8192), stdoutEncoding, true);
			}

			if (startInfo.RedirectStandardError) {
				MonoIO.Close (stderr_write, out error);

				Encoding stderrEncoding = startInfo.StandardErrorEncoding ?? Console.Out.Encoding;

				process.error_stream = new StreamReader (new FileStream (stderr_read, FileAccess.Read, true, 8192), stderrEncoding, true);
			}

			process.StartBackgroundWaitForExit ();

			return true;
		}
예제 #23
0
        public void Launch()
        {
            var appPath = System.Environment.ExpandEnvironmentVariables(appDef.ExeFullPath);

            // try to adopt an already running process (matching by process image file name, regardless of path)
            if (appDef.AdoptIfAlreadyRunning)
            {
                ProcInfo found = FindProcessByExeName(appPath);
                if (found != null)
                {
                    log.DebugFormat("Adopted existing process pid={0}, cmd=\"{1}\", dir=\"{2}\"", found.Process.Id, found.CmdLine, found.Process.StartInfo.WorkingDirectory);
                    proc = found.Process;
                    return;
                }
            }


            // set environment variables here so we can use them when expanding process path/args/cwd
            Environment.SetEnvironmentVariable("DIRIGENT_MACHINEID", appDef.AppIdTuple.MachineId);
            Environment.SetEnvironmentVariable("DIRIGENT_APPID", appDef.AppIdTuple.AppId);

            // start the process
            var psi = new ProcessStartInfo();

            psi.FileName = BuildAbsolutePath(appPath);
            if (appDef.CmdLineArgs != null)
            {
                psi.Arguments = System.Environment.ExpandEnvironmentVariables(appDef.CmdLineArgs);
            }
            if (appDef.StartupDir != null)
            {
                var dir = System.Environment.ExpandEnvironmentVariables(appDef.StartupDir);
                psi.WorkingDirectory = BuildAbsolutePath(dir);
            }
            psi.WindowStyle = appDef.WindowStyle;

            psi.UseShellExecute = false;             // allows us using environment variables

            //
            // modify the environment
            //
            foreach (var x in appDef.EnvVarsToSet)
            {
                var name  = x.Key;
                var value = System.Environment.ExpandEnvironmentVariables(x.Value);
                psi.EnvironmentVariables[name] = value;
            }
            if (!String.IsNullOrEmpty(appDef.EnvVarPathToAppend))
            {
                var name    = "PATH";
                var postfix = System.Environment.ExpandEnvironmentVariables(appDef.EnvVarPathToAppend);
                // if relative path is specified, consider it relative to SharedConfig and make it absolute (per each ';' separated segment)
                postfix = string.Join(";", postfix.Split(';').Select(p => BuildAbsolutePath(p)));
                psi.EnvironmentVariables[name] = psi.EnvironmentVariables[name] + ";" + postfix;
            }
            if (!String.IsNullOrEmpty(appDef.EnvVarPathToPrepend))
            {
                var name   = "PATH";
                var prefix = System.Environment.ExpandEnvironmentVariables(appDef.EnvVarPathToPrepend);
                // if relative path is specified, consider it relative to SharedConfig and make it absolute (per each ';' separated segment)
                prefix = string.Join(";", prefix.Split(';').Select(p => BuildAbsolutePath(p)));
                psi.EnvironmentVariables[name] = prefix + ";" + psi.EnvironmentVariables[name];
            }

            try
            {
                log.DebugFormat("StartProc exe \"{0}\", cmd \"{1}\", dir \"{2}\", windowstyle {3}", psi.FileName, psi.Arguments, psi.WorkingDirectory, psi.WindowStyle);
                proc = Process.Start(psi);
                if (proc != null)
                {
                    log.DebugFormat("StartProc SUCCESS pid {0}", proc.Id);
                }
                else
                {
                    log.DebugFormat("StartProc FAILED (no details)");
                }
            }
            catch (Exception ex)
            {
                log.DebugFormat("StartProc FAILED except {0}", ex.Message);
                throw new AppStartFailureException(appDef.AppIdTuple, ex.Message, ex);
            }
        }
예제 #24
0
파일: Process.cs 프로젝트: zdpdev/mono
        bool StartWithCreateProcess(ProcessStartInfo startInfo)
        {
            if (startInfo.StandardOutputEncoding != null && !startInfo.RedirectStandardOutput)
            {
                throw new InvalidOperationException(SR.GetString(SR.StandardOutputEncodingNotAllowed));
            }

            if (startInfo.StandardErrorEncoding != null && !startInfo.RedirectStandardError)
            {
                throw new InvalidOperationException(SR.GetString(SR.StandardErrorEncodingNotAllowed));
            }

            if (this.disposed)
            {
                throw new ObjectDisposedException(GetType().Name);
            }

            var procInfo = new ProcInfo();

            if (startInfo.HaveEnvVars)
            {
                List <string> envVariables = null;
                StringBuilder sb           = null;

                foreach (DictionaryEntry de in startInfo.EnvironmentVariables)
                {
                    if (de.Value == null)
                    {
                        continue;
                    }

                    if (envVariables == null)
                    {
                        envVariables = new List <string> ();
                    }

                    if (sb == null)
                    {
                        sb = new StringBuilder();
                    }
                    else
                    {
                        sb.Clear();
                    }

                    sb.Append((string)de.Key);
                    sb.Append('=');
                    sb.Append((string)de.Value);

                    envVariables.Add(sb.ToString());
                }

                procInfo.envVariables = envVariables?.ToArray();
            }

            MonoIOError error;
            IntPtr      stdin_read = IntPtr.Zero, stdin_write = IntPtr.Zero;
            IntPtr      stdout_read = IntPtr.Zero, stdout_write = IntPtr.Zero;
            IntPtr      stderr_read = IntPtr.Zero, stderr_write = IntPtr.Zero;

            try {
                if (startInfo.RedirectStandardInput)
                {
                    CreatePipe(out stdin_read, out stdin_write, true);
                }
                else
                {
                    stdin_read  = MonoIO.ConsoleInput;
                    stdin_write = IntPtr.Zero;
                }

                if (startInfo.RedirectStandardOutput)
                {
                    CreatePipe(out stdout_read, out stdout_write, false);
                }
                else
                {
                    stdout_read  = IntPtr.Zero;
                    stdout_write = MonoIO.ConsoleOutput;
                }

                if (startInfo.RedirectStandardError)
                {
                    CreatePipe(out stderr_read, out stderr_write, false);
                }
                else
                {
                    stderr_read  = IntPtr.Zero;
                    stderr_write = MonoIO.ConsoleError;
                }

                FillUserInfo(startInfo, ref procInfo);

                //
                // FIXME: For redirected pipes we need to send descriptors of
                // stdin_write, stdout_read, stderr_read to child process and
                // close them there (fork makes exact copy of parent's descriptors)
                //
                if (!CreateProcess_internal(startInfo, stdin_read, stdout_write, stderr_write, ref procInfo))
                {
                    throw new Win32Exception(-procInfo.pid, "ApplicationName='" + startInfo.FileName + "', CommandLine='" + startInfo.Arguments +
                                             "', CurrentDirectory='" + startInfo.WorkingDirectory + "', Native error= " + Win32Exception.GetErrorMessage(-procInfo.pid));
                }
            } catch {
                if (startInfo.RedirectStandardInput)
                {
                    if (stdin_read != IntPtr.Zero)
                    {
                        MonoIO.Close(stdin_read, out error);
                    }
                    if (stdin_write != IntPtr.Zero)
                    {
                        MonoIO.Close(stdin_write, out error);
                    }
                }

                if (startInfo.RedirectStandardOutput)
                {
                    if (stdout_read != IntPtr.Zero)
                    {
                        MonoIO.Close(stdout_read, out error);
                    }
                    if (stdout_write != IntPtr.Zero)
                    {
                        MonoIO.Close(stdout_write, out error);
                    }
                }

                if (startInfo.RedirectStandardError)
                {
                    if (stderr_read != IntPtr.Zero)
                    {
                        MonoIO.Close(stderr_read, out error);
                    }
                    if (stderr_write != IntPtr.Zero)
                    {
                        MonoIO.Close(stderr_write, out error);
                    }
                }

                throw;
            } finally {
                if (procInfo.Password != IntPtr.Zero)
                {
                    Marshal.ZeroFreeBSTR(procInfo.Password);
                    procInfo.Password = IntPtr.Zero;
                }
            }

            SetProcessHandle(new SafeProcessHandle(procInfo.process_handle, true));
            SetProcessId(procInfo.pid);

#pragma warning disable 618

            if (startInfo.RedirectStandardInput)
            {
                MonoIO.Close(stdin_read, out error);

#if MOBILE
                var stdinEncoding = Encoding.Default;
#else
                var stdinEncoding = Console.InputEncoding;
#endif
                standardInput = new StreamWriter(new FileStream(stdin_write, FileAccess.Write, true, 8192), stdinEncoding)
                {
                    AutoFlush = true
                };
            }

            if (startInfo.RedirectStandardOutput)
            {
                MonoIO.Close(stdout_write, out error);

                Encoding stdoutEncoding = startInfo.StandardOutputEncoding ?? Console.OutputEncoding;

                standardOutput = new StreamReader(new FileStream(stdout_read, FileAccess.Read, true, 8192), stdoutEncoding, true);
            }

            if (startInfo.RedirectStandardError)
            {
                MonoIO.Close(stderr_write, out error);

                Encoding stderrEncoding = startInfo.StandardErrorEncoding ?? Console.OutputEncoding;

                standardError = new StreamReader(new FileStream(stderr_read, FileAccess.Read, true, 8192), stderrEncoding, true);
            }
#pragma warning restore

            return(true);
        }
예제 #25
0
파일: Process.cs 프로젝트: BrzVlad/mono
		bool StartWithCreateProcess (ProcessStartInfo startInfo)
		{
			if (startInfo.StandardOutputEncoding != null && !startInfo.RedirectStandardOutput)
				throw new InvalidOperationException (SR.GetString(SR.StandardOutputEncodingNotAllowed));

			if (startInfo.StandardErrorEncoding != null && !startInfo.RedirectStandardError)
				throw new InvalidOperationException (SR.GetString(SR.StandardErrorEncodingNotAllowed));

			if (this.disposed)
				throw new ObjectDisposedException (GetType ().Name);

			var procInfo = new ProcInfo ();

			if (startInfo.HaveEnvVars) {
				List<string> envVariables = null;
				StringBuilder sb = null;

				foreach (DictionaryEntry de in startInfo.EnvironmentVariables) {
					if (de.Value == null)
						continue;

					if (envVariables == null)
						envVariables = new List<string> ();

					if (sb == null)
						sb = new StringBuilder ();
					else
						sb.Clear ();

					sb.Append ((string) de.Key);
					sb.Append ('=');
					sb.Append ((string) de.Value);

					envVariables.Add (sb.ToString ());
				}

				procInfo.envVariables = envVariables?.ToArray ();
			}

			MonoIOError error;
			IntPtr stdin_read = IntPtr.Zero, stdin_write = IntPtr.Zero;
			IntPtr stdout_read = IntPtr.Zero, stdout_write = IntPtr.Zero;
			IntPtr stderr_read = IntPtr.Zero, stderr_write = IntPtr.Zero;

			try {
				if (startInfo.RedirectStandardInput) {
					CreatePipe (out stdin_read, out stdin_write, true);
				} else {
					stdin_read = MonoIO.ConsoleInput;
					stdin_write = IntPtr.Zero;
				}

				if (startInfo.RedirectStandardOutput) {
					CreatePipe (out stdout_read, out stdout_write, false);
				} else {
					stdout_read = IntPtr.Zero;
					stdout_write = MonoIO.ConsoleOutput;
				}

				if (startInfo.RedirectStandardError) {
					CreatePipe (out stderr_read, out stderr_write, false);
				} else {
					stderr_read = IntPtr.Zero;
					stderr_write = MonoIO.ConsoleError;
				}

				FillUserInfo (startInfo, ref procInfo);

				//
				// FIXME: For redirected pipes we need to send descriptors of
				// stdin_write, stdout_read, stderr_read to child process and
				// close them there (fork makes exact copy of parent's descriptors)
				//
				if (!CreateProcess_internal (startInfo, stdin_read, stdout_write, stderr_write, ref procInfo)) {
					throw new Win32Exception (-procInfo.pid, "ApplicationName='" + startInfo.FileName + "', CommandLine='" + startInfo.Arguments +
						"', CurrentDirectory='" + startInfo.WorkingDirectory + "', Native error= " + Win32Exception.GetErrorMessage (-procInfo.pid));
				}
			} catch {
				if (startInfo.RedirectStandardInput) {
					if (stdin_read != IntPtr.Zero)
						MonoIO.Close (stdin_read, out error);
					if (stdin_write != IntPtr.Zero)
						MonoIO.Close (stdin_write, out error);
				}

				if (startInfo.RedirectStandardOutput) {
					if (stdout_read != IntPtr.Zero)
						MonoIO.Close (stdout_read, out error);
					if (stdout_write != IntPtr.Zero)
						MonoIO.Close (stdout_write, out error);
				}

				if (startInfo.RedirectStandardError) {
					if (stderr_read != IntPtr.Zero)
						MonoIO.Close (stderr_read, out error);
					if (stderr_write != IntPtr.Zero)
						MonoIO.Close (stderr_write, out error);
				}

				throw;
			} finally {
				if (procInfo.Password != IntPtr.Zero) {
					Marshal.ZeroFreeBSTR (procInfo.Password);
					procInfo.Password = IntPtr.Zero;
				}
			}

			SetProcessHandle (new SafeProcessHandle (procInfo.process_handle, true));
			SetProcessId (procInfo.pid);
			
#pragma warning disable 618

			if (startInfo.RedirectStandardInput) {
				MonoIO.Close (stdin_read, out error);

#if MOBILE
				var stdinEncoding = Encoding.Default;
#else
				var stdinEncoding = Console.InputEncoding;
#endif
				standardInput = new StreamWriter (new FileStream (stdin_write, FileAccess.Write, true, 8192), stdinEncoding) {
					AutoFlush = true
				};
			}

			if (startInfo.RedirectStandardOutput) {
				MonoIO.Close (stdout_write, out error);

				Encoding stdoutEncoding = startInfo.StandardOutputEncoding ?? Console.Out.Encoding;

				standardOutput = new StreamReader (new FileStream (stdout_read, FileAccess.Read, true, 8192), stdoutEncoding, true);
			}

			if (startInfo.RedirectStandardError) {
				MonoIO.Close (stderr_write, out error);

				Encoding stderrEncoding = startInfo.StandardErrorEncoding ?? Console.Out.Encoding;

				standardError = new StreamReader (new FileStream (stderr_read, FileAccess.Read, true, 8192), stderrEncoding, true);
			}
#pragma warning restore

			return true;
		}
예제 #26
0
 private static bool ShellExecuteEx_internal(ProcessStartInfo startInfo,
                                             ref ProcInfo proc_info)
 {
     throw new System.NotImplementedException();
 }
예제 #27
0
		public override IEnumerator OnProcess ( ProcInfo pi )
		{
			yield return null;
		}
예제 #28
0
파일: Process.cs 프로젝트: kumpera/mono
		private static bool Start_shell (ProcessStartInfo startInfo,
						 Process process)
		{
			ProcInfo proc_info=new ProcInfo();
			bool ret;

			if (startInfo.RedirectStandardInput ||
			    startInfo.RedirectStandardOutput ||
			    startInfo.RedirectStandardError) {
				throw new InvalidOperationException ("UseShellExecute must be false when redirecting I/O.");
			}

			if (startInfo.HaveEnvVars)
				throw new InvalidOperationException ("UseShellExecute must be false in order to use environment variables.");

			FillUserInfo (startInfo, ref proc_info);
			try {
				ret = ShellExecuteEx_internal (startInfo,
							       ref proc_info);
			} finally {
				if (proc_info.Password != IntPtr.Zero)
					Marshal.FreeBSTR (proc_info.Password);
				proc_info.Password = IntPtr.Zero;
			}
			if (!ret) {
				throw new Win32Exception (-proc_info.pid);
			}

			process.process_handle = proc_info.process_handle;
			process.pid = proc_info.pid;

			process.StartExitCallbackIfNeeded ();

			return(ret);
		}
예제 #29
0
파일: Process.cs 프로젝트: kumpera/mono
		private extern static bool ShellExecuteEx_internal(ProcessStartInfo startInfo,
								   ref ProcInfo proc_info);
예제 #30
0
        bool StartWithCreateProcess(ProcessStartInfo startInfo)
        {
            if (startInfo.StandardOutputEncoding != null && !startInfo.RedirectStandardOutput)
            {
                throw new InvalidOperationException(SR.GetString(SR.StandardOutputEncodingNotAllowed));
            }

            if (startInfo.StandardErrorEncoding != null && !startInfo.RedirectStandardError)
            {
                throw new InvalidOperationException(SR.GetString(SR.StandardErrorEncodingNotAllowed));
            }

            if (this.disposed)
            {
                throw new ObjectDisposedException(GetType().Name);
            }

            var proc_info = new ProcInfo();

            if (startInfo.HaveEnvVars)
            {
                string [] strs = new string [startInfo.EnvironmentVariables.Count];
                startInfo.EnvironmentVariables.Keys.CopyTo(strs, 0);
                proc_info.envKeys = strs;

                strs = new string [startInfo.EnvironmentVariables.Count];
                startInfo.EnvironmentVariables.Values.CopyTo(strs, 0);
                proc_info.envValues = strs;
            }

            MonoIOError error;
            IntPtr      stdin_read = IntPtr.Zero, stdin_write = IntPtr.Zero;
            IntPtr      stdout_read = IntPtr.Zero, stdout_write = IntPtr.Zero;
            IntPtr      stderr_read = IntPtr.Zero, stderr_write = IntPtr.Zero;

            try {
                if (startInfo.RedirectStandardInput)
                {
                    CreatePipe(out stdin_read, out stdin_write, true);
                }
                else
                {
                    stdin_read  = MonoIO.ConsoleInput;
                    stdin_write = IntPtr.Zero;
                }

                if (startInfo.RedirectStandardOutput)
                {
                    CreatePipe(out stdout_read, out stdout_write, false);
                }
                else
                {
                    stdout_read  = IntPtr.Zero;
                    stdout_write = MonoIO.ConsoleOutput;
                }

                if (startInfo.RedirectStandardError)
                {
                    CreatePipe(out stderr_read, out stderr_write, false);
                }
                else
                {
                    stderr_read  = IntPtr.Zero;
                    stderr_write = MonoIO.ConsoleError;
                }

                FillUserInfo(startInfo, ref proc_info);

                //
                // FIXME: For redirected pipes we need to send descriptors of
                // stdin_write, stdout_read, stderr_read to child process and
                // close them there (fork makes exact copy of parent's descriptors)
                //
                if (!CreateProcess_internal(startInfo, stdin_read, stdout_write, stderr_write, ref proc_info))
                {
                    throw new Win32Exception(-proc_info.pid, "ApplicationName='" + startInfo.FileName + "', CommandLine='" + startInfo.Arguments +
                                             "', CurrentDirectory='" + startInfo.WorkingDirectory + "', Native error= " + Win32Exception.W32ErrorMessage(-proc_info.pid));
                }
            } catch {
                if (startInfo.RedirectStandardInput)
                {
                    if (stdin_read != IntPtr.Zero)
                    {
                        MonoIO.Close(stdin_read, out error);
                    }
                    if (stdin_write != IntPtr.Zero)
                    {
                        MonoIO.Close(stdin_write, out error);
                    }
                }

                if (startInfo.RedirectStandardOutput)
                {
                    if (stdout_read != IntPtr.Zero)
                    {
                        MonoIO.Close(stdout_read, out error);
                    }
                    if (stdout_write != IntPtr.Zero)
                    {
                        MonoIO.Close(stdout_write, out error);
                    }
                }

                if (startInfo.RedirectStandardError)
                {
                    if (stderr_read != IntPtr.Zero)
                    {
                        MonoIO.Close(stderr_read, out error);
                    }
                    if (stderr_write != IntPtr.Zero)
                    {
                        MonoIO.Close(stderr_write, out error);
                    }
                }

                throw;
            } finally {
                if (proc_info.Password != IntPtr.Zero)
                {
                    Marshal.ZeroFreeBSTR(proc_info.Password);
                    proc_info.Password = IntPtr.Zero;
                }
            }

            SetProcessHandle(new SafeProcessHandle(proc_info.process_handle, true));
            SetProcessId(proc_info.pid);

            if (startInfo.RedirectStandardInput)
            {
                //
                // FIXME: The descriptor needs to be closed but due to wapi io-layer
                // not coping with duplicated descriptors any StandardInput write fails
                //
                // MonoIO.Close (stdin_read, out error);

#if MOBILE
                var stdinEncoding = Encoding.Default;
#else
                var stdinEncoding = Console.InputEncoding;
#endif
                standardInput = new StreamWriter(new FileStream(stdin_write, FileAccess.Write, true, 8192), stdinEncoding)
                {
                    AutoFlush = true
                };
            }

            if (startInfo.RedirectStandardOutput)
            {
                MonoIO.Close(stdout_write, out error);

                Encoding stdoutEncoding = startInfo.StandardOutputEncoding ?? Console.Out.Encoding;

                standardOutput = new StreamReader(new FileStream(stdout_read, FileAccess.Read, true, 8192), stdoutEncoding, true);
            }

            if (startInfo.RedirectStandardError)
            {
                MonoIO.Close(stderr_write, out error);

                Encoding stderrEncoding = startInfo.StandardErrorEncoding ?? Console.Out.Encoding;

                standardError = new StreamReader(new FileStream(stderr_read, FileAccess.Read, true, 8192), stderrEncoding, true);
            }

            return(true);
        }
예제 #31
0
파일: Process.cs 프로젝트: zdpdev/mono
 private extern static bool CreateProcess_internal(ProcessStartInfo startInfo, IntPtr stdin, IntPtr stdout, IntPtr stderr, ref ProcInfo procInfo);
예제 #32
0
 private void ProcOnExited(ProcInfo proc)
 {
     lstView.RemoveObject(proc);
 }
예제 #33
0
		private static bool ShellExecuteEx_internal(ProcessStartInfo startInfo,
		ref ProcInfo proc_info)
		{
			throw new System.NotImplementedException();
		}
예제 #34
0
		public abstract IEnumerator OnProcess ( ProcInfo pi ) ;
예제 #35
0
        //disable this function on production
        public JsonResult GetProcParamters(JObject data)
        {
            ProcInfo pinfo = new ProcInfo(data["procedure_name"].ToString(), data["conn_str"].ToString());

            return(JsonNet(GetParamters(pinfo)));
        }
예제 #36
0
파일: Process.cs 프로젝트: BrzVlad/mono
		bool StartWithShellExecuteEx (ProcessStartInfo startInfo)
		{
			if (this.disposed)
				throw new ObjectDisposedException (GetType ().Name);

			if (!String.IsNullOrEmpty(startInfo.UserName) || (startInfo.Password != null))
				throw new InvalidOperationException(SR.GetString(SR.CantStartAsUser));

			if (startInfo.RedirectStandardInput || startInfo.RedirectStandardOutput || startInfo.RedirectStandardError)
				throw new InvalidOperationException(SR.GetString(SR.CantRedirectStreams));

			if (startInfo.StandardErrorEncoding != null)
				throw new InvalidOperationException(SR.GetString(SR.StandardErrorEncodingNotAllowed));

			if (startInfo.StandardOutputEncoding != null)
				throw new InvalidOperationException(SR.GetString(SR.StandardOutputEncodingNotAllowed));

			// can't set env vars with ShellExecuteEx...
			if (startInfo.environmentVariables != null)
				throw new InvalidOperationException(SR.GetString(SR.CantUseEnvVars));

			ProcInfo procInfo = new ProcInfo();
			bool ret;

			FillUserInfo (startInfo, ref procInfo);
			try {
				ret = ShellExecuteEx_internal (startInfo, ref procInfo);
			} finally {
				if (procInfo.Password != IntPtr.Zero)
					Marshal.ZeroFreeBSTR (procInfo.Password);
				procInfo.Password = IntPtr.Zero;
			}
			if (!ret) {
				throw new Win32Exception (-procInfo.pid);
			}

			SetProcessHandle (new SafeProcessHandle (procInfo.process_handle, true));
			SetProcessId (procInfo.pid);

			return ret;
		}
예제 #37
0
 private string ProcStr(ProcInfo proc)
 {
     return($"{proc.Name} ({proc.Id})");
 }
예제 #38
0
파일: Process.cs 프로젝트: kumpera/mono
		// Note that ProcInfo.Password must be freed.
		private static void FillUserInfo (ProcessStartInfo startInfo, ref ProcInfo proc_info)
		{
#if NET_2_0
			if (startInfo.UserName != null) {
				proc_info.UserName = startInfo.UserName;
				proc_info.Domain = startInfo.Domain;
				if (startInfo.Password != null)
					proc_info.Password = Marshal.SecureStringToBSTR (startInfo.Password);
				else
					proc_info.Password = IntPtr.Zero;
				proc_info.LoadUserProfile = startInfo.LoadUserProfile;
			}
#endif
		}
예제 #39
0
		private static bool CreateProcess_internal(ProcessStartInfo startInfo,
		IntPtr stdin,
		IntPtr stdout,
		IntPtr stderr,
		ref ProcInfo proc_info)
		{
			throw new System.NotImplementedException();
		}
예제 #40
0
파일: Process.cs 프로젝트: kumpera/mono
		private extern static bool CreateProcess_internal(ProcessStartInfo startInfo,
								  IntPtr stdin,
								  IntPtr stdout,
								  IntPtr stderr,
								  ref ProcInfo proc_info);
예제 #41
0
파일: WeChatController.cs 프로젝트: vdcan/-
        //事件
        public string EventHandle(XmlDocument xmldoc)
        {
            string  responseContent = "";
            XmlNode Event           = xmldoc.SelectSingleNode("/xml/Event");
            XmlNode EventKey        = xmldoc.SelectSingleNode("/xml/EventKey");
            XmlNode ToUserName      = xmldoc.SelectSingleNode("/xml/ToUserName");
            XmlNode FromUserName    = xmldoc.SelectSingleNode("/xml/FromUserName");

            if (Event != null)
            {
                JObject data = new JObject();


                ProcInfo pi = new ProcInfo();

                if (Event.InnerText.Equals("subscribe"))
                {
                    if (EventKey.InnerText != "")
                    {
                        var    b   = System.Convert.FromBase64String(EventKey.InnerText.Replace("qrscene_", ""));
                        string b64 = System.Text.Encoding.UTF8.GetString(b);
                        data["key"] = b64;
                    }
                    else
                    {
                        data["key"] = "";
                    }

                    pi.ProcedureName = "vdp_wechat_subscribe";
                }
                if (Event.InnerText.Equals("unsubscribe"))
                {
                    //  data["event"] = EventKey.InnerText;

                    //var b = System.Convert.FromBase64String(EventKey.InnerText);
                    //string b64 = System.Text.Encoding.UTF8.GetString(b);

                    //data["key"] = b64;
                    pi.ProcedureName = "vdp_wechat_unsubscribe";
                }

                if (Event.InnerText.Equals("SCAN"))
                {
                    var    b   = System.Convert.FromBase64String(EventKey.InnerText);
                    string b64 = System.Text.Encoding.UTF8.GetString(b);

                    data["key"]      = b64;
                    pi.ProcedureName = "vdp_wechat_scan";

                    //Ticket
                }
                if (Event.InnerText.Equals("scancode_push"))
                {
                    data["event"] = EventKey.InnerText;
                }

                //菜单单击事件
                if (Event.InnerText.Equals("CLICK"))
                {
                    data["event"] = EventKey.InnerText;

                    pi.ProcedureName = "vdp_wechat_event_click";
                }//菜单单击事件
                if (Event.InnerText.Equals("VIEW"))
                {
                    data["event"] = EventKey.InnerText;

                    pi.ProcedureName = "vdp_wechat_event_view";
                }

                data["from_user_name"] = FromUserName.InnerText;
                data["to_user_name"]   = ToUserName.InnerText;
                pi.Type    = "proc";
                pi.ConnStr = "app";
                DataSet ds = RunProcedureDataSet(data, pi);

                responseContent = ProcessResult(ds, xmldoc);
            }
            return(responseContent);
        }
예제 #42
0
파일: Process.cs 프로젝트: kumpera/mono
		private static bool Start_noshell (ProcessStartInfo startInfo,
						   Process process)
		{
			ProcInfo proc_info=new ProcInfo();
			IntPtr stdin_rd = IntPtr.Zero, stdin_wr = IntPtr.Zero;
			IntPtr stdout_wr;
			IntPtr stderr_wr;
			bool ret;
			MonoIOError error;

			if (startInfo.HaveEnvVars) {
				string [] strs = new string [startInfo.EnvironmentVariables.Count];
				startInfo.EnvironmentVariables.Keys.CopyTo (strs, 0);
				proc_info.envKeys = strs;

				strs = new string [startInfo.EnvironmentVariables.Count];
				startInfo.EnvironmentVariables.Values.CopyTo (strs, 0);
				proc_info.envValues = strs;
			}

			if (startInfo.RedirectStandardInput == true) {
				if (IsWindows) {
					int DUPLICATE_SAME_ACCESS = 0x00000002;
					IntPtr stdin_wr_tmp;

					ret = MonoIO.CreatePipe (out stdin_rd,
									 out stdin_wr_tmp);
					if (ret) {
						ret = MonoIO.DuplicateHandle (Process.GetCurrentProcess ().Handle, stdin_wr_tmp,
						Process.GetCurrentProcess ().Handle, out stdin_wr, 0, 0, DUPLICATE_SAME_ACCESS);
						MonoIO.Close (stdin_wr_tmp, out error);
					}
				}
				else
				{
					ret = MonoIO.CreatePipe (out stdin_rd,
									 out stdin_wr);
				}
				if (ret == false) {
					throw new IOException ("Error creating standard input pipe");
				}
			} else {
				stdin_rd = MonoIO.ConsoleInput;
				/* This is required to stop the
				 * &$*£ing stupid compiler moaning
				 * that stdin_wr is unassigned, below.
				 */
				stdin_wr = (IntPtr)0;
			}

			if (startInfo.RedirectStandardOutput == true) {
				IntPtr out_rd = IntPtr.Zero;
				if (IsWindows) {
					IntPtr out_rd_tmp;
					int DUPLICATE_SAME_ACCESS = 0x00000002;

					ret = MonoIO.CreatePipe (out out_rd_tmp,
									 out stdout_wr);
					if (ret) {
						MonoIO.DuplicateHandle (Process.GetCurrentProcess ().Handle, out_rd_tmp,
						Process.GetCurrentProcess ().Handle, out out_rd, 0, 0, DUPLICATE_SAME_ACCESS);
						MonoIO.Close (out_rd_tmp, out error);
					}
				}
				else {
					ret = MonoIO.CreatePipe (out out_rd,
									 out stdout_wr);
				}

				process.stdout_rd = out_rd;
				if (ret == false) {
					if (startInfo.RedirectStandardInput == true) {
						MonoIO.Close (stdin_rd, out error);
						MonoIO.Close (stdin_wr, out error);
					}

					throw new IOException ("Error creating standard output pipe");
				}
			} else {
				process.stdout_rd = (IntPtr)0;
				stdout_wr = MonoIO.ConsoleOutput;
			}

			if (startInfo.RedirectStandardError == true) {
				IntPtr err_rd = IntPtr.Zero;
				if (IsWindows) {
					IntPtr err_rd_tmp;
					int DUPLICATE_SAME_ACCESS = 0x00000002;

					ret = MonoIO.CreatePipe (out err_rd_tmp,
									 out stderr_wr);
					if (ret) {
						MonoIO.DuplicateHandle (Process.GetCurrentProcess ().Handle, err_rd_tmp,
						Process.GetCurrentProcess ().Handle, out err_rd, 0, 0, DUPLICATE_SAME_ACCESS);
						MonoIO.Close (err_rd_tmp, out error);
					}
				}
				else {
					ret = MonoIO.CreatePipe (out err_rd,
									 out stderr_wr);
				}

				process.stderr_rd = err_rd;
				if (ret == false) {
					if (startInfo.RedirectStandardInput == true) {
						MonoIO.Close (stdin_rd, out error);
						MonoIO.Close (stdin_wr, out error);
					}
					if (startInfo.RedirectStandardOutput == true) {
						MonoIO.Close (process.stdout_rd, out error);
						MonoIO.Close (stdout_wr, out error);
					}
					
					throw new IOException ("Error creating standard error pipe");
				}
			} else {
				process.stderr_rd = (IntPtr)0;
				stderr_wr = MonoIO.ConsoleError;
			}

			FillUserInfo (startInfo, ref proc_info);
			try {
				ret = CreateProcess_internal (startInfo,
							      stdin_rd, stdout_wr, stderr_wr,
							      ref proc_info);
			} finally {
				if (proc_info.Password != IntPtr.Zero)
					Marshal.FreeBSTR (proc_info.Password);
				proc_info.Password = IntPtr.Zero;
			}
			if (!ret) {
				if (startInfo.RedirectStandardInput == true) {
					MonoIO.Close (stdin_rd, out error);
					MonoIO.Close (stdin_wr, out error);
				}

				if (startInfo.RedirectStandardOutput == true) {
					MonoIO.Close (process.stdout_rd, out error);
					MonoIO.Close (stdout_wr, out error);
				}

				if (startInfo.RedirectStandardError == true) {
					MonoIO.Close (process.stderr_rd, out error);
					MonoIO.Close (stderr_wr, out error);
				}

				throw new Win32Exception (-proc_info.pid,
					"ApplicationName='" + startInfo.FileName +
					"', CommandLine='" + startInfo.Arguments +
					"', CurrentDirectory='" + startInfo.WorkingDirectory +
					"', Native error= " + Win32Exception.W32ErrorMessage (-proc_info.pid));
			}

			process.process_handle = proc_info.process_handle;
			process.pid = proc_info.pid;
			
			if (startInfo.RedirectStandardInput == true) {
				MonoIO.Close (stdin_rd, out error);
				process.input_stream = new StreamWriter (new MonoSyncFileStream (stdin_wr, FileAccess.Write, true, 8192), Console.Out.Encoding);
				process.input_stream.AutoFlush = true;
			}

#if NET_2_0
			Encoding stdoutEncoding = startInfo.StandardOutputEncoding ?? Console.Out.Encoding;
			Encoding stderrEncoding = startInfo.StandardErrorEncoding ?? Console.Out.Encoding;
#else
			Encoding stdoutEncoding = Console.Out.Encoding;
			Encoding stderrEncoding = stdoutEncoding;
#endif

			if (startInfo.RedirectStandardOutput == true) {
				MonoIO.Close (stdout_wr, out error);
				process.output_stream = new StreamReader (new MonoSyncFileStream (process.stdout_rd, FileAccess.Read, true, 8192), stdoutEncoding, true, 8192);
			}

			if (startInfo.RedirectStandardError == true) {
				MonoIO.Close (stderr_wr, out error);
				process.error_stream = new StreamReader (new MonoSyncFileStream (process.stderr_rd, FileAccess.Read, true, 8192), stderrEncoding, true, 8192);
			}

			process.StartExitCallbackIfNeeded ();

			return(ret);
		}
예제 #43
0
 public ProcessWatcher(string procName)
 {
     ProcInfo = new ProcInfo(procName);
 }