コード例 #1
0
ファイル: NativeMethods.cs プロジェクト: Orvid/Cosmos
 public static extern int CreateProcess(
     string applicationName,
     string commandLine,
     SECURITY_ATTRIBUTES processAttributes,
     SECURITY_ATTRIBUTES threadAttributes,
     bool bInheritHandles,
     int dwCreationFlags,
     IntPtr environment,
     string currentDirectory,
     STARTUPINFO startupInfo,
     PROCESS_INFORMATION processInformation);
コード例 #2
0
ファイル: Debugger.cs プロジェクト: fedorw/monodevelop
        public CorProcess CreateProcess (
                                         String                      applicationName,
                                         String                      commandLine,
                                         SECURITY_ATTRIBUTES         processAttributes,
                                         SECURITY_ATTRIBUTES         threadAttributes,
                                         bool                        inheritHandles,
                                         int                         creationFlags,
                                         IntPtr                      environment,  
                                         String                      currentDirectory,
                                         STARTUPINFO                 startupInfo,
                                         ref PROCESS_INFORMATION     processInformation,
                                         CorDebugCreateProcessFlags  debuggingFlags)
        {
            /*
             * If commandLine is: <c:\a b\a arg1 arg2> and c:\a.exe does not exist, 
             *    then without this logic, "c:\a b\a.exe" would be tried next.
             * To prevent this ambiguity, this forces the user to quote if the path 
             *    has spaces in it: <"c:\a b\a" arg1 arg2>
             */
            if(null == applicationName && !commandLine.StartsWith("\""))
            {
                int firstSpace = commandLine.IndexOf(" ");
                if(firstSpace != -1)
                    commandLine = String.Format(CultureInfo.InvariantCulture, "\"{0}\" {1}", commandLine.Substring(0,firstSpace), commandLine.Substring(firstSpace, commandLine.Length-firstSpace));
            }

            ICorDebugProcess proc = null;

            m_debugger.CreateProcess (
                                  applicationName, 
                                  commandLine, 
                                  processAttributes,
                                  threadAttributes, 
                                  inheritHandles ? 1 : 0, 
                                  (uint) creationFlags, 
                                  environment, 
                                  currentDirectory, 
                                  startupInfo, 
                                  processInformation, 
                                  debuggingFlags,
                                  out proc);

            return CorProcess.GetCorProcess(proc);
        }
コード例 #3
0
ファイル: Debugger.cs プロジェクト: fedorw/monodevelop
		// [Xamarin] Output redirection.
		void CreateHandles (STARTUPINFO si, out SafeFileHandle outReadPipe, out SafeFileHandle errorReadPipe)
		{
			si.dwFlags |= 0x00000100; /*STARTF_USESTDHANDLES*/
			SECURITY_ATTRIBUTES sa = new SECURITY_ATTRIBUTES ();
			sa.bInheritHandle = true;
			IntPtr curProc = NativeMethods.GetCurrentProcess ();

			SafeFileHandle outWritePipe, outReadPipeTmp;
			if (!NativeMethods.CreatePipe (out outReadPipeTmp, out outWritePipe, sa, 0))
				throw new Exception ("Pipe creation failed");

			// Create the child error pipe.
			SafeFileHandle errorWritePipe, errorReadPipeTmp;
			if (!NativeMethods.CreatePipe (out errorReadPipeTmp, out errorWritePipe, sa, 0))
				throw new Exception ("Pipe creation failed");

			// Create new output read and error read handles. Set
			// the Properties to FALSE. Otherwise, the child inherits the
			// properties and, as a result, non-closeable handles to the pipes
			// are created.
			if (!NativeMethods.DuplicateHandle (curProc, outReadPipeTmp, curProc, out outReadPipe, 0, false, NativeMethods.DUPLICATE_SAME_ACCESS))
				throw new Exception ("Pipe creation failed");
			if (!NativeMethods.DuplicateHandle (curProc, errorReadPipeTmp, curProc, out errorReadPipe, 0, false, NativeMethods.DUPLICATE_SAME_ACCESS))
				throw new Exception ("Pipe creation failed");

			NativeMethods.CloseHandle (curProc);

			// Close inheritable copies of the handles you do not want to be
			// inherited.
			outReadPipeTmp.Close ();
			errorReadPipeTmp.Close ();

			si.hStdInput = NativeMethods.GetStdHandle (NativeMethods.STD_INPUT_HANDLE);
			si.hStdOutput = outWritePipe;
			si.hStdError = errorWritePipe;
		}
コード例 #4
0
ファイル: Debugger.cs プロジェクト: fedorw/monodevelop
		// [Xamarin] ASP.NET Debugging and output redirection.
        /**
         * Launch a process under the control of the debugger.
         *
         * Parameters are the same as the Win32 CreateProcess call.
         */
        public CorProcess CreateProcess (
                                         String applicationName,
                                         String commandLine,
                                         String currentDirectory,
										 IDictionary<string,string> environment,
                                         int    flags
                                         )
        {
            PROCESS_INFORMATION pi = new PROCESS_INFORMATION ();

            STARTUPINFO si = new STARTUPINFO ();
            si.cb = Marshal.SizeOf(si);

            // initialize safe handles 
			SafeFileHandle outReadPipe = null, errorReadPipe = null;
			if ((flags & CREATE_REDIRECT_STD) != 0) {
				CreateHandles (si, out outReadPipe, out errorReadPipe);
				flags &= ~CREATE_REDIRECT_STD;
			}
			else {
				si.hStdInput = new SafeFileHandle (IntPtr.Zero, false);
				si.hStdOutput = new SafeFileHandle (IntPtr.Zero, false);
				si.hStdError = new SafeFileHandle (IntPtr.Zero, false);
			}

			IntPtr env = IntPtr.Zero;
			if (environment != null) {
				string senv = null;
				foreach (KeyValuePair<string, string> var in environment) {
					senv += var.Key + "=" + var.Value + "\0";
				}
				senv += "\0";
				env = Marshal.StringToHGlobalAnsi (senv);
			}

            CorProcess ret;

            //constrained execution region (Cer)
            System.Runtime.CompilerServices.RuntimeHelpers.PrepareConstrainedRegions();
            try 
            {
            } 
            finally
            {
                ret = CreateProcess (
                                     applicationName,
                                     commandLine, 
                                     null,
                                     null,
                                     true,   // inherit handles
                                     flags,  // creation flags
									 env,      // environment
                                     currentDirectory,
                                     si,     // startup info
                                     ref pi, // process information
                                     CorDebugCreateProcessFlags.DEBUG_NO_SPECIAL_OPTIONS);
                NativeMethods.CloseHandle (pi.hProcess);
                NativeMethods.CloseHandle (pi.hThread);
            }

			if (env != IntPtr.Zero)
				Marshal.FreeHGlobal (env);

			if (outReadPipe != null) {

				// Close pipe handles (do not continue to modify the parent).
				// You need to make sure that no handles to the write end of the
				// output pipe are maintained in this process or else the pipe will
				// not close when the child process exits and the ReadFile will hang.

				si.hStdInput.Close ();
				si.hStdOutput.Close ();
				si.hStdError.Close ();

				ret.TrackStdOutput (outReadPipe, errorReadPipe);
			}

			return ret;
        }
コード例 #5
0
ファイル: Debugger.cs プロジェクト: Orvid/Cosmos
 public CorProcess CreateProcess(
                                  String applicationName,
                                  String commandLine,
                                  SECURITY_ATTRIBUTES processAttributes,
                                  SECURITY_ATTRIBUTES threadAttributes,
                                  bool inheritHandles,
                                  int creationFlags,
                                  IntPtr environment,
                                  String currentDirectory,
                                  STARTUPINFO startupInfo,
                                  ref PROCESS_INFORMATION processInformation,
                                  CorDebugCreateProcessFlags debuggingFlags)
 {
     return CreateProcess(null,
                          applicationName,
                          commandLine,
                          processAttributes,
                          threadAttributes,
                          inheritHandles,
                          creationFlags,
                          environment,
                          currentDirectory,
                          startupInfo,
                          ref processInformation,
                          debuggingFlags);
 }
コード例 #6
0
ファイル: Debugger.cs プロジェクト: Orvid/Cosmos
        public CorProcess CreateProcess(String applicationName,
                                        String commandLine,
                                        String currentDirectory,
                                        int flags,
                                        CorRemoteTarget target)
        {
            PROCESS_INFORMATION pi = new PROCESS_INFORMATION();

            STARTUPINFO si = new STARTUPINFO();
            si.cb = Marshal.SizeOf(si);

            // initialize safe handles 
            si.hStdInput = new Microsoft.Win32.SafeHandles.SafeFileHandle(new IntPtr(0), false);
            si.hStdOutput = new Microsoft.Win32.SafeHandles.SafeFileHandle(new IntPtr(0), false);
            si.hStdError = new Microsoft.Win32.SafeHandles.SafeFileHandle(new IntPtr(0), false);

            CorProcess ret;

            //constrained execution region (Cer)
            System.Runtime.CompilerServices.RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
            }
            finally
            {
                ret = CreateProcess(target,
                                     applicationName,
                                     commandLine,
                                     null,
                                     null,
                                     true,   // inherit handles
                                     flags,  // creation flags
                                     new IntPtr(0),      // environment
                                     currentDirectory,
                                     si,     // startup info
                                     ref pi, // process information
                                     CorDebugCreateProcessFlags.DEBUG_NO_SPECIAL_OPTIONS);
                NativeMethods.CloseHandle(pi.hProcess);
                NativeMethods.CloseHandle(pi.hThread);
            }

            return ret;
        }
コード例 #7
0
ファイル: Silverlight.cs プロジェクト: Orvid/Cosmos
        public static int CreateProc(
            string applicationName,
            string commandLine,
            SECURITY_ATTRIBUTES processAttributes,
            SECURITY_ATTRIBUTES threadAttributes,
            bool bInheritHandles,
            int dwCreationFlags,
            IntPtr environment,
            string currentDirectory,
            STARTUPINFO startupInfo,
            ref PROCESS_INFORMATION processInformation)
        {
            int iRet = NativeMethods.CreateProcess(
                                applicationName,
                                commandLine,
                                processAttributes,
                                threadAttributes,
                                bInheritHandles,
                                dwCreationFlags,
                                environment,
                                currentDirectory,
                                startupInfo,
                                processInformation);

            if (0 == iRet)
            {
                CommandBase.WriteError("CreateProcess failed in Silverlight Extension: " + Marshal.GetLastWin32Error());
                CommandBase.WriteError("    CreateProcess-ApplicationName=" + applicationName);
                CommandBase.WriteError("    CreateProcess-commandLine=" + commandLine);
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }

            return iRet;
        }
コード例 #8
0
		internal static void TearDownOutputRedirection (SafeFileHandle outReadPipe, SafeFileHandle errorReadPipe, STARTUPINFO si, CorProcess ret)
		{
			if (outReadPipe != null) {
				// Close pipe handles (do not continue to modify the parent).
				// You need to make sure that no handles to the write end of the
				// output pipe are maintained in this process or else the pipe will
				// not close when the child process exits and the ReadFile will hang.

				si.hStdInput.Close ();
				si.hStdOutput.Close ();
				si.hStdError.Close ();

				ret.TrackStdOutput (outReadPipe, errorReadPipe);
			}
		}
コード例 #9
0
		internal static void SetupOutputRedirection (STARTUPINFO si, ref int flags, out SafeFileHandle outReadPipe, out SafeFileHandle errorReadPipe)
		{
			if ((flags & CREATE_REDIRECT_STD) != 0) {
				CreateHandles (si, out outReadPipe, out errorReadPipe);
				flags &= ~CREATE_REDIRECT_STD;
			}
			else {
				outReadPipe = null;
				errorReadPipe = null;
				si.hStdInput = new SafeFileHandle (IntPtr.Zero, false);
				si.hStdOutput = new SafeFileHandle (IntPtr.Zero, false);
				si.hStdError = new SafeFileHandle (IntPtr.Zero, false);
			}
		}
コード例 #10
0
        /**
         * Launch a process under the control of the debugger.
         *
         * Parameters are the same as the Win32 CreateProcess call.
         */
        public CorProcess CreateProcess (
                                         String applicationName,
                                         String commandLine,
                                         String currentDirectory,
										 IDictionary<string,string> environment,
                                         int    flags
                                         )
        {
            PROCESS_INFORMATION pi = new PROCESS_INFORMATION ();

            STARTUPINFO si = new STARTUPINFO ();
            si.cb = Marshal.SizeOf(si);

            // initialize safe handles 
			// [Xamarin] ASP.NET Debugging and output redirection.
			SafeFileHandle outReadPipe = null, errorReadPipe = null;
			DebuggerExtensions.SetupOutputRedirection (si, ref flags, out outReadPipe, out errorReadPipe);
			IntPtr env = DebuggerExtensions.SetupEnvironment (environment);

            CorProcess ret;

            //constrained execution region (Cer)
            System.Runtime.CompilerServices.RuntimeHelpers.PrepareConstrainedRegions();
            try 
            {
            } 
            finally
            {
                ret = CreateProcess (
                                     applicationName,
                                     commandLine, 
                                     null,
                                     null,
                                     true,   // inherit handles
                                     flags,  // creation flags
									 env,      // environment
                                     currentDirectory,
                                     si,     // startup info
                                     ref pi, // process information
                                     CorDebugCreateProcessFlags.DEBUG_NO_SPECIAL_OPTIONS);
                NativeMethods.CloseHandle (pi.hProcess);
                NativeMethods.CloseHandle (pi.hThread);
            }

			DebuggerExtensions.TearDownEnvironment (env);
			DebuggerExtensions.TearDownOutputRedirection (outReadPipe, errorReadPipe, si, ret);

            return ret;
        }
コード例 #11
0
 public virtual extern void CreateProcess([In, MarshalAs(UnmanagedType.LPWStr)] string lpApplicationName, [In, MarshalAs(UnmanagedType.LPWStr)] string lpCommandLine, [In] SECURITY_ATTRIBUTES lpProcessAttributes, [In] SECURITY_ATTRIBUTES lpThreadAttributes, [In] int bInheritHandles, [In] uint dwCreationFlags, [In] IntPtr lpEnvironment, [In, MarshalAs(UnmanagedType.LPWStr)] string lpCurrentDirectory, [In, ComAliasName("Microsoft.Debugging.CorDebug.NativeApi.ULONG_PTR")] STARTUPINFO lpStartupInfo, [In, ComAliasName("Microsoft.Debugging.CorDebug.NativeApi.ULONG_PTR")] PROCESS_INFORMATION lpProcessInformation, [In] CorDebugCreateProcessFlags debuggingFlags, [MarshalAs(UnmanagedType.Interface)] out ICorDebugProcess ppProcess);