Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start-ChocolateyProcessAsAdmin.ps1 errors when running PowerShell scripts #1220

Closed
tek0011 opened this issue Mar 30, 2017 · 5 comments
Closed

Comments

@tek0011
Copy link

tek0011 commented Mar 30, 2017

What You Are Seeing?

On 0.10.4 I am getting back a try/catch error. I have a gist of it working in 0.10.3 and failing in 0.10.4. Currently this is for the tomcat module. I haven't checked or seen issues in other modules yet.

gist

What is Expected?

No errors.

How Did You Get This To Happen? (Steps to Reproduce)

Our Puppet system upgraded servers to 0.10.4, attempted to install the tomcat module and received this failure.

Output Log

See above gist

Notes

This reverts what was implemented with #1126

@skyguy94
Copy link

skyguy94 commented Mar 30, 2017

Its related to this change: e208ca2#diff-208a9466943493065fc7c68d8479cdccR118

I'm calling Start-ChocolateyProcessAsAdmin like this:


Push-Location (Join-Path $catalinaHome 'bin')
Start-ChocolateyProcessAsAdmin ".\service.bat install $($options['serviceName'])"
Pop-Location

and I'm getting the error:

ERROR: The term '      try {
        .\service.bat install Tomcat8
      } catch {
       throw
      }' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

I'm not sure why the change is causing it to fail, but I do think the push-location should be part of the Start- call's arguments so I'm making that modification.

@ferventcoder
Copy link
Member

ferventcoder commented Mar 30, 2017

@skyguy94 I think your script has a possible bug in it. We always say full paths to files. Always.

Before we started up PowerShell from the location of the script, which may have allowed it to work properly.

However this bug seems to be depended on, so we need to fix it. There is more to this than just that that is errorring, and it's a gating issue.

@skyguy94
Copy link

That could be, I'll fix it up to specify the full path, but I'm seeing the issue in a new provisioned server with chef too:

DotNet3.5 v3.5.20160716 [Approved]

dotnet3.5 package files install completed. Performing other installation steps.

ERROR: The term '      try {

        cmd.exe /c DISM /Online /NoRestart /Enable-Feature /FeatureName:NetFx3ServerFeatures

      } catch {

       throw

      }' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of th
e name, or if a path was included, verify that the path is correct and try again.

The install of dotnet3.5 was NOT successful.

Error while running 'C:\ProgramData\chocolatey\lib\DotNet3.5\Tools\ChocolateyInstall.ps1'.

 See log for details.

@skyguy94
Copy link

I think its more of an issue with the try...catch and the call & operator. This test fails too:

Windows PowerShell
Copyright (C) 2016 Microsoft Corporation. All rights reserved.

Loading personal and system profiles took 1219ms.
C:\WINDOWS\system32> $block = "try { cmd.exe } catch { throw }"
C:\WINDOWS\system32> & $block
& : The term 'try { cmd.exe } catch { throw }' is not recognized as the name of a cmdlet, function, script file, or
operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
again.
At line:1 char:3
+ & $block
+   ~~~~~~
    + CategoryInfo          : ObjectNotFound: (try { cmd.exe } catch { throw }:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

C:\WINDOWS\system32> $block = "try { C:\Windows\system32\cmd.exe } catch { throw }"
C:\WINDOWS\system32> & $block
& : The term 'try { C:\Windows\system32\cmd.exe } catch { throw }' is not recognized as the name of a cmdlet,
function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the
path is correct and try again.
At line:1 char:3
+ & $block
+   ~~~~~~
    + CategoryInfo          : ObjectNotFound: (try { C:\Window...catch { throw }:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

C:\WINDOWS\system32> C:\Windows\System32\cmd.exe

@ferventcoder
Copy link
Member

I'm seeing that as well. We are working to turn around 0.10.5 to get this fixed ASAP.

@ferventcoder ferventcoder changed the title Start-ChocolateyProcessAsAdmin.ps1 ERROR Start-ChocolateyProcessAsAdmin.ps1 errors when running PowerShell scripts Mar 30, 2017
ferventcoder added a commit that referenced this issue Mar 30, 2017
With GH-1126 at e208ca2, the change to just run a script block
didn't work in all cases for already elevated processes.

Instead of wrapping it, just set it up as a script block and invoke the
script block.
ferventcoder added a commit that referenced this issue Mar 30, 2017
Use old encoded command method for now. It works well although it puts
a lot of CLIXML into stderr and onto the screen when it runs.
ferventcoder added a commit that referenced this issue Mar 30, 2017
* stable:
  (version) 0.10.5
  (doc) update CHANGELOG/nuspec
  (GH-1224) support longer timeouts
  (doc) update CHANGELOG/nuspec
  (GH-1222) choco outdated -r output - no header
  (maint) update NuGet.Core
  (GH-1220) Use old method
  (GH-1220) Fix: PowerShell blocks fail in Start-ChocolateyProcessAsAdmin
  (doc) update CHANGELOG/nuspec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants