程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了通过 Powershell 执行 Accoreconsole.exe 时出现问题大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决通过 PowersHell 执行 Accoreconsole.exe 时出现问题?

开发过程中遇到通过 PowersHell 执行 Accoreconsole.exe 时出现问题的问题如何解决?下面主要结合日常开发的经验,给出你关于通过 PowersHell 执行 Accoreconsole.exe 时出现问题的解决方法建议,希望对你解决通过 PowersHell 执行 Accoreconsole.exe 时出现问题有所启发或帮助;

我正在尝试运行一个 .ps1,它允许用户从 windows 对话框中选择文件,然后选择他们希望在每个文件上运行的脚本。然后对于这些文件中的每一个,打开 autoCAD Core Console 并进行处理。

当我使用 .bat 或直接通过 CMD 运行文件和脚本时,我没有任何问题。当我尝试运行下面的 PowersHell 脚本时,我让 Accoreconsole.exe 启动,但它立即关闭。同样的脚本在以前的机器上运行,所以我想知道它是否与安全或执行策略有关?

AcCoreConsole 需要以下格式的输入。我的 powersHell 脚本所做的就是尝试重新创建与此类似的路径。

AcCoreConsole.exe [/i] /s [/product] [/l] [/isolate] [/Readonly] [/p[rofile] ]

Set-ExecutionPolicy -ExecutionPolicy UnreStricted
#Sets username for initial path and script path
$env:Username

#Initial path to project Sheets directory
$initialDirectory = "C:\Users\$env:Username\Desktop\PW Exports\test\"

#Initial path to project Script directory 
$scriptDirectory = "C:\Users\$env:Username\Desktop\PW Exports\test\" 

#number of instances of the autoCAD Core Console at one time - Recommended 5
$Accoreinstance = 1

#This sets the variable for CAD files in an array or List as String values
[array]$CADF = @()
$CADF = Get-CADfiles

#This sets the variable for your script file in an array or List as String values
[array]$SCR = @()
$SCR = Get-Script

#This to bring up windows dialog prompt to SELEct CAD files to be processed
Function Get-CADfiles($CADF)
{
    [System.Reflection.Assembly]::LoaDWithPartialname("System.windows.forms") | Out-Null

    $OpenfileDialog = New-Object System.windows.Forms.OpenfileDialog
    $OpenfileDialog.InitialDirectory = $initialDirectory
    $OpenfileDialog.MultiSELEct = $true
    $OpenfileDialog.title = "Choose CAD files The you wish To Process"
    $OpenfileDialog.ShowDialog() | Out-Null
    $OpenfileDialog.filenames
}

#This to allow for a second windows dialog promt to SELEct the script to be run on the files above
Function Get-Script($SCR)
{
    $OpenfileDialog = New-Object System.windows.Forms.OpenfileDialog
    $OpenfileDialog.InitialDirectory = $scriptDirectory
    $OpenfileDialog.title = "Choose Script file To Run"
    $OpenfileDialog.ShowDialog() | Out-Null
    $OpenfileDialog.filename
}

$CADF_List = get-item $CADF
#This takes the SELEcted files from windows dialog and processes
foreach ($file in $CADF_List) {

    #This is to count the number of current AcCore running
    $running = @(Get-Job | Where-Object {$_.State -eq 'Running'})

    #This will wait until the number of instances is lower than what was set on with $Accoreinstance
    if ($running.Count -ge $AccoreinstancE) {
        $running | Wait-Job -Any | Out-Null
    }

    Write-Host "StarTing to process $file"

    #This will start the running of script on the files
    Start-Job -ScriptBlock {

    #This is where you set which version of Accore you are going to be using to run
    $AccoreVrs = "C:\Program files\autodesk\autoCAD 2020\accoreconsole.exe"
    $arg1 = ' /i ' + $using:file + ' /s ' + $using:SCR 

    # Start the core-console for each instance and set the job to wait until it finishes
    start-process $AccoreVrs $arg1 -wait

    } | Out-Null

}

# Wait for all jobs to complete and results ready to be received
get-job | Wait-Job | Out-Null

# Process the results
foreach($Accoreinstance in Get-Job)
{
    $result = Receive-Job $Accoreinstance
    Write-Host $result
}

Remove-Job -State Completed

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

大佬总结

以上是大佬教程为你收集整理的通过 Powershell 执行 Accoreconsole.exe 时出现问题全部内容,希望文章能够帮你解决通过 Powershell 执行 Accoreconsole.exe 时出现问题所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。