使用NodeJS安装Chocolatey软件包时出现问题

时间:2019-11-01 23:01:14

标签: node.js powershell batch-file electron chocolatey

我已经编写了一个带有React UI的Electron应用程序,该UI使用渲染器和主进程。作为要求的一部分,我建立了一个UI列表,其中包含可以安装的Chocolatey软件包。我有一个执行命令的Powershell脚本模块。我已经成功安装了软件包管理器,但是在使用powershell脚本模块时安装软件包时遇到了问题。这真让我抓狂。在终端中执行时,安装工作正常。我不确定自己做错了什么,但对我的帮助非常感谢。

这是执行终端命令的代码部分。

电子收到命令

ipc.on(Actions.INSTALL_CHOCO_PACKAGE, (event, args) => {   
    logger.info(`[INSTALL_CHOCO_PACKAGGE] - powershell Install-Package -Item ${args}'`);
    execInstallPackage(`powershell Install-Package -Item ${args}`, event);

});

节点执行命令



    async function execInstallPackage(argument, event){
            logger.info(`Executing command ${argument}`)
             childProcess =  exec(
            argument,
        ( error, stdout, stderr ) =>
                some output is performed

这是Powershell脚本模块中的功能

    function Install-Package {
       [CmdletBinding()]
        param(
            [string[]]$Item,

        )

        if($Item.count -gt 1){
            forEach($package in $Item){
                Start-Process cmd -Verb RunAs -ArgumentList '/c choco install $($package) -dfvy'
                #cmd /c "choco install $($package) -dfvy"
            }   
        }
        else {
            Write-Output "--Executing $($Item)" 

            Set-ExecutionPolicy Bypass -Scope Process -Force 
            choco install $Item -dfvy
        }
    }

我尝试使用两种不同的方法,但得到相同的错误:

*2019-11-01 10:19:58,107 14332 [INFO ] - 
Firefox v70.0.1 (forced) [Approved]
2019-11-01 10:19:58,116 14332 [INFO ] - firefox package files install completed. Performing other installation steps.
2019-11-01 10:19:58,281 14332 [ERROR] - firefox not installed. An error occurred during installation:
 Item has already been added. Key in dictionary: 'Path'  Key being added: 'PATH'
2019-11-01 10:19:58,290 14332 [WARN ] - 
Chocolatey installed 0/0 packages. 
 See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
2019-11-01 10:19:58,292 14332 [WARN ] - 
Did you know the proceeds of Pro (and some proceeds from other
 licensed editions) go into bettering the community infrastructure?
 Your support ensures an active community, keeps Chocolatey tip top,
 plus it nets you some awesome features!
 https://chocolatey.org/compare
2019-11-01 10:19:58,293 14332 [DEBUG] - Sending message 'PostRunMessage' out if there are subscribers...
2019-11-01 10:19:58,302 14332 [ERROR] - The process cannot access the file 'C:\ProgramData\chocolatey\lib\Firefox\.chocolateyPending' because it is being used by another process.
2019-11-01 10:19:58,305 14332 [ERROR] - More Details: System.IO.IOException: The process cannot access the file 'C:\ProgramData\chocolatey\lib\Firefox\.chocolateyPending' because it is being used by another process.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
   at chocolatey.infrastructure.filesystem.DotNetFileSystem.get_file_encoding(String filePath)
   at chocolatey.infrastructure.filesystem.DotNetFileSystem.write_file(String filePath, String fileText)
   at chocolatey.infrastructure.app.services.ChocolateyPackageService.set_pending(PackageResult packageResult, ChocolateyConfiguration config)
   at chocolatey.infrastructure.app.services.ChocolateyPackageService.handle_package_result(PackageResult packageResult, ChocolateyConfiguration config, CommandNameType commandName)
   at chocolatey.infrastructure.app.services.NugetService.install_run(ChocolateyConfiguration config, Action`1 continueAction)
   at chocolatey.infrastructure.app.services.ChocolateyPackageService.perform_source_runner_function[T](ChocolateyConfiguration config, Func`2 function)
   at chocolatey.infrastructure.app.services.ChocolateyPackageService.install_run(ChocolateyConfiguration config)
   at chocolatey.infrastructure.app.runners.GenericRunner.run(ChocolateyConfiguration config, Container container, Boolean isConsole, Action`1 parseArgs)
   at chocolatey.infrastructure.app.runners.ConsoleApplication.run(String[] args, ChocolateyConfiguration config, Container container)
   at chocolatey.console.Program.Main(String[] args)
2019-11-01 10:19:58,306 14332 [DEBUG] - Exiting with 1
2019-11-01 13:43:28,540 17184 [DEBUG] - XmlConfiguration is now operational
2019-11-01 13:43:28,572 17184 [INFO ] - ============================================================*

0 个答案:

没有答案