Pash.Implementation.ExecutionContext.SetSuccessVariable C# (CSharp) Method

SetSuccessVariable() private method

private SetSuccessVariable ( bool success ) : void
success bool
return void
        internal void SetSuccessVariable(bool success)
        {
            PSVariable questionMarkVariable = SessionState.PSVariable.GetAtScope("?", "global");
            if (questionMarkVariable != null)
            {
                questionMarkVariable.Value = success;
            }
        }

Usage Example

示例#1
0
        private Collection <PSObject> ExecuteScriptInSessionState(string path, SessionState sessionState)
        {
            var scriptBlock     = new ExternalScriptInfo(path, ScopeUsages.CurrentScope).ScriptBlock;
            var originalContext = _executionContext;
            var scopedContext   = _executionContext.Clone(sessionState, ScopeUsages.CurrentScope);

            try
            {
                // actually change the scope by changing the execution context
                // there should definitely be a nicer way for this #ExecutionContextChange
                _executionContext = scopedContext;
                _executionContext.CurrentRunspace.ExecutionContext = scopedContext;
                return(scriptBlock.Invoke()); // TODO: pass parameters if set
            }
            catch (ExitException e)
            {
                var exitCode = LanguagePrimitives.ConvertTo <int>(e.Argument);
                _executionContext.SetLastExitCodeVariable(exitCode);
                _executionContext.SetSuccessVariable(exitCode == 0);
                return(new Collection <PSObject>()
                {
                    PSObject.AsPSObject(e.Argument)
                });
            }
            finally
            {
                // restore original context / scope
                _executionContext.CurrentRunspace.ExecutionContext = originalContext;
                _executionContext = originalContext;
            }
        }
All Usage Examples Of Pash.Implementation.ExecutionContext::SetSuccessVariable