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

SetLastExitCodeVariable() private method

private SetLastExitCodeVariable ( int exitCode ) : void
exitCode int
return void
        internal void SetLastExitCodeVariable(int exitCode)
        {
            SetVariable("global:LASTEXITCODE", exitCode);
        }

Usage Example

Ejemplo n.º 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::SetLastExitCodeVariable